NOTE: The topic described in this section is optional and may require knowledge of scripting with ServiceNow APIs.

In ServiceNow, you can create your own Perspectium Action to perform custom monitoring and send in your own events. For example, you may want to monitor the total number of tasks created daily.

You can do this by leveraging the PerspectiumObserver script include that comes as part of the Perspectium Core Update Set for ServiceNow.  The following functions are available for use in the PerspectiumObserver script include: 

Function

Arguments

postTuple

  • type
  • name
  • value
postDailyTableAggregates
  • tableName
  • eventName
  • aggField
postTableAggregates
  • tableName
  • eventName
  • aggField
  • encodedQuery
postSecondsAgoTableAggregates
  • tableName
  • eventName
  • aggField
  • fromDateStr
  • secondsAgo

Procedure


To create a Perspectium Action for custom monitoring, follow these steps:

1. Log into ServiceNow and navigate to ObserverActions. Then, click New to create a new Perspectium Action record.

2. Enter any Name for your Perspectium Action. Choose the Start and End dates for when you want to execute your Perspectium Action. Then, check the Active checkbox.

3. Under Script, add your desired script to send ServiceNow data to Observer as a metric. The following is an example script for a custom Perspectium Action that will monitor the number of tasks created daily using the postTuple function:

try {
var psp = new Perspectium();
var o = new PerspectiumObserver();

// Calculate total number of tasks created today 
var sc = new GlideRecord('task');
sc.addEncodedQuery('sys_created_onONToday@javascript:gs.daysAgoStart(0)@javascript:gs.daysAgoEnd(0)');
sc.query();
// postTuple() is a function that can be called to create messages with metrics to send to Observer
// it should be passed the parameters "statsx", name of the metric, value of the metric
o.postTuple("statsx", "Tasks Created Today", sc.getRowCount());
} catch (e) {
var logger = new PerspectiumLogger();
logger.logError("error= " + e, "Action.Tasks Created Today");

psp.updateStatus("status", "error: " + e);
}

4. Click Submit to finish creating your Perspectium Action.

Next Steps


To monitor your newly created Perspectium Action, see create a custom alert.