The CreatorCon Call for Content is officially open! Get started here.

Getting a Return value from Syslog Probe?

Hoppertron
Giga Contributor

Does anyone know if it's possible to get a return value after invoking the Syslog probe script include which confirms which MID agent the syslog probe task was queued for?  Or know a clever way around it?

After submitting a syslog task to the ECC Queue, I'd like to know (in code) which MID agent the task was assigned to (e.g. if failover or load balancing clusters were invoked because the target MID server was down).

My current workaround is to query the ECC Queue using GlideRecord (where queue = output, topic = syslog, and sys_created_on = time of submission) but this is imprecise and prone to failure.

At the moment it seems like you can't even get a 'success' response back.

Here's an example of the code I'm currently using:

var gdt = new GlideDateTime(); // Get the current DateTime

var sl = new Syslog(
		'my-syslog-server.domain.com', // Target syslog collection server
		'MyMidServer1', // Target MID server
		16              // syslog facility code
		);
		sl.timestamp = gdt.toString(); // Time of submission
		sl.log("This is test of MID server failover clusters at " + gdt.toString(), 6);


// Code below is purely to find out which MID server agent the task went to
var gr = new GlideRecord('ecc_queue');
gr.addQuery("topic=Syslog^queue=output");
gr.addQuery('sys_created_on',gdt.getValue());
gr.query();
while (gr.next()){
	gs.print("Syslog sent at: " + gr.sys_created_on + ", Sent to: " + gr.agent + ", Payload:" + gr.payload);
}

 

1 REPLY 1

Hoppertron
Giga Contributor

Ok, it looks like the SncProbe.insert method returns a GUID for the ecc_queue record that it creates.

So, if I call the SncProbe class directly (instead of using the Syslog class) then I can get the info I want.

Example:

var mid_server = 'mid.server.'; // MID server name always needs to start with 'mid.server.'
var mid_server += 'MyMidServerName'; // Append my target MID server's name
var dst_host = 'MySyslogServer.domain.com'; // Hostname of target Syslog server
var src_host = gs.getProperty('instance_name');

var probe = new SncProbe();
	// Default Syslog probe params mostly taken from the Syslog script include.
      probe.setTopic('Syslog');
	  probe.addParameter(	  'skip_sensor', 	  'true' 		);
      probe.addParameter(     'syslog_facility',  '16'   		);
      probe.addParameter(     'syslog_priority',  '6'    		);
      probe.addParameter(     'syslog_bsd_style', 'true' 		);
      probe.addParameter(     'syslog_port',      '514'  		);
      probe.addParameter(     'syslog_dst_host',  dst_host      );
      probe.addParameter(     'syslog_message',   'Testing MID server probe stuff'	);
      probe.addParameter(     'syslog_app_name',  'natsdev.servicenow.com'      	);
      if (src_host)
          probe.addParameter( 'syslog_src_host',  src_host      );
	  probe.addParameter( 'syslog_app_id',    null       );
      probe.addParameter( 'syslog_msg_id',    null       );
      probe.addParameter( 'syslog_timestamp', null       );
      probe.addParameter( 'syslog_timezone',  null       );

var eccSysId = probe.insert(mid_server); // Insert the probe into the ECC queue and store the resulting Sys_Id

var gr = GlideRecord('ecc_queue');
gr.get(eccSysId);

gs.print(gr.agent);

This could be neater if I created a new class that extends the OOTB Syslog class, but I'm not sure it's worthwhile for this one requirement?

If anyone has any better ideas, please shout!