Example #1
0
// Send is used to send message to ygord. TODO: replace this by an sqschan.
func Send(message string) error {
	log.Printf("send to ygord: %s", message)
	if cfg.TestMode {
		return nil
	}

	if cfg.YgordQueueName == "" {
		return nil
	}

	client, err := sqs.NewClient(cfg.AWSAccessKeyID, cfg.AWSSecretAccessKey,
		cfg.AWSRegionCode)
	if err != nil {
		return err
	}

	url, err := client.GetQueueURL(cfg.YgordQueueName)
	if err != nil {
		return err
	}

	err = client.SendMessage(url, sqs.SQSEncode(message))
	if err != nil {
		return err
	}

	return nil
}
Example #2
0
// SendToChannelMinions sends a message to all the minions of the given
// channel.
func SendToChannelMinions(channel, msg string) {
	client, err := sqs.NewClient(cfg.AWSAccessKeyID, cfg.AWSSecretAccessKey,
		cfg.AWSRegionCode)
	if err != nil {
		Debug("error: " + err.Error())
		return
	}

	channelCfg, exists := cfg.Channels[channel]
	if !exists {
		Debug("error: " + channel + " has no queue(s) configured")
		return
	}

	urls, err := channelCfg.GetQueueURLs()
	if err != nil {
		Debug("error: unable to load queue URLs, " + err.Error())
		return
	}

	// Send the same exact data to all this channel's minion.
	for _, url := range urls {
		if cfg.TestMode {
			fmt.Printf("[SQS-SendToMinion] %s %s\n", url, msg)
			continue
		}

		err := client.SendMessage(url, sqs.SQSEncode(msg))
		if err != nil {
			Debug("error sending to minion: " + err.Error())
			continue
		}
	}
}
Example #3
0
// SendToQueue sends a message to our friendly minion via its SQS queue.
func (srv *Server) SendToQueue(queueURL, msg string) {
	srv.OutputQueue <- &OutputMessage{
		Type:     OutMsgTypeMinion,
		QueueURL: queueURL,
		Body:     sqs.SQSEncode(msg),
	}
}
Example #4
0
// StartIRCOutgoingQueueWriter writes all the messages from the outgoing channel.
func StartIRCOutgoingQueueWriter(client *sqs.Client) (<-chan error, error) {
	ch, errch, err := sqschan.Outgoing(client, cfg.IRCOutgoingQueueName)
	if err != nil {
		return nil, err
	}

	go func() {
		for {
			ch <- sqs.SQSEncode(<-IRCOutgoing)
		}
	}()

	return errch, nil
}
Example #5
0
// SendToChannelMinions sends a message to all the minions of the given
// channel.
func (srv *Server) SendToChannelMinions(channel, msg string) {
	urls, err := srv.GetQueueURLsByChannel(channel)
	if err != nil {
		log.Printf("error: unable to load queue URLs, %s", err.Error())
		return
	}

	// Send the same exact data to all this channel's minion.
	for _, url := range urls {
		srv.OutputQueue <- &OutputMessage{
			Type:     OutMsgTypeMinion,
			QueueURL: url,
			Body:     sqs.SQSEncode(msg),
		}
	}

	for _, client := range srv.GetClientsByChannel(channel) {
		if client.IsAlive() {
			client.Queue <- msg
		} else {
			srv.PurgeClient(client)
		}
	}
}