Moogsoft Docs

RabbitMQ

The RabbitMQ module allows you to broadcast information on a RabbitMQ bus . For example, you can use it to push alert or Situation data to a data warehouse via RabbitMQ.

You cannot connect the RabbitMQ Moobot module to the RabbitMQ instance used by Moogsoft AIOps.

Configure the Module

To use the RabbitMQ Moobot module:

  1. Define a new global object rabbit at the top of a Moobot JavaScript file to load the module.
  2. Use the connect method to create a new connection to one or more RabbitMQ brokers.
  3. Use the send method to send the required information.
  4. Use the close method to close the connection.

Refer to the examples for more details.

Reference Guide

You can use the f ollowing methods in the RabbitMQ Moobot module.

connect

Establishes a connection to one or more RabbitMQ brokers with defined connection properties.

You cannot connect the RabbitMQ Moobot module to the RabbitMQ instance used by Moogsoft AIOps.

Request Argument

Name Type Description
<properties>
Object A JavaScript object containing connection properties. See below.

RabbitMQ Connection Properties

The RabbitMQ module connect method defines connection properties as a Javascript object, which may include the following keys:

Key Description
brokers

Top-level container for one or more target RabbitMQ brokers. For each broker, define:

  • host : Hostname or IP address of the RabbitMQ broker.
  • port : Port of the RabbitMQ broker.
user Username to connect to RabbitMQ.
password Username to connect to RabbitMQ.
timeout Length of time to wait before halting a connection or read attempt, in milliseconds. Defaults to 10,000.
vhost Name of the RabbitMQ virtual host. Optional.
ssl Top-level container for the SSL configuration. Optional.
ssl_protocol The SSL protocol to use. If not specified, TLSv1.2 is used by default.
server_cert_file Name of the SSL root CA file.
client_cert_file Name of the SSL client certificate.
client_key_file Name of the SSL client key file. Must be in PKCS#8 format. Refer to Message System SSL for more information.

Return Parameter

Type Description
Object A Java object containing connection details, depending on the requested connection properties.
Returns null if no connection can be made.

Example

{
    brokers: [
		{
			host: "rabbithost",
            port: 5672
        }
    ],
    user: "rabbitmq_admin",
    password: "78smr9!b",
    timeout: 10000,
    vhost: "rabbitvhost",
    ssl: {
		ssl_protocol: "TLSv1.2",
        server_cert_file: "server.pem",
        client_cert_file: "client.pem",
        client_key_file: "client.key"
    }
}

send

Sends a message to the RabbitMQ broker. Refer to the basic class in the RabbitMQ AMQP 0-9-1 Reference for a list of keys that you can specify in the message properties.

Name Type Description
Exchange String The RabbitMQ exchange.
RoutingKey String The RabbitMQ routing key.
Properties String or Object

Message properties in one of the following formats:

  • Plain text
  • JSON Object payload
  • JSON Array payload
Message String The message to send.

Return Parameter

None.

Examples

connection.send("direct_logs", "severity", 
	{
		content-type : "text/xml",
		reply-to	 : "greetings.hi",
		headers		 : {"server" "app5.myapp.megacorp.com" "cached" false}
	},
	"<Priority>1</Priority>"
)

connection.send("topic_logs", "topic", {contentType: "text/xml"}, "<Priority>1</Priority>");

close

Closes the connection to the RabbitMQ broker.

Request Argument

None.

Return Parameter

Type Description
Boolean Indicates if the close operation was successful: true = success, false = fail.

Examples

The following examples demonstrate the use of the RabbitMQ Moobot modules:

var rabbit = MooBot.loadModule('RabbitMQ'); 
var connection = rabbit.connect({  
   brokers:[  
      {  
         host:"myHost",
         port:5672
      }
   ],
   user:"test",
   password:"test",
   timeout:10000,
   vhost:"myVHost",
   ssl:{  
      ssl_protocol:"TLSv1.2",
      server_cert_file:"server.pem",
      client_cert_file:"client.pem",
      client_key_file:"client.key"
   }
});

if (connection) {
    connection.send("test", "test", {contentType: "text/xml"}, "<testKey>testValue</testKey>");
    connection.send("test", "test", {testKey: "value"});
    connection.send("test", "test", ["value"]);
    connection.send("test", "test", "testValue");
    connection.close();
}
// Load the module
var rabbit = MooBot.loadModule('RabbitMQ');

// Create a new connection
var connection = rabbit.connect({  
   brokers:[  
      {  
         host:"rabbithost",
         port:5672
      }
   ],
   user:"rabbitmq_admin",
   password:"78smr9!b",
   timeout:10000,
   vhost:"rabbitvhost",
   ssl:{  
      ssl_protocol:"TLSv1.2",
      server_cert_file:"server.pem",
      client_cert_file:"client.pem",
      client_key_file:"client.key"
   }
});

if (connection) {
    // Send information
    connection.send("testExchange", "testRoutingKey", ["one", "two"]);

    // Close the connection
    connection.close();
}