ServiceNow Event Management Integration with iCinga2

Hello

Icinga2 has out of box script to integrate with ServiceNow event management. Not sure who wrote the script (ServiceNow or Icinga2 team) but it works OK.

What I found (may be wrong) would have been great if the custom data fields attached to a particular host / service is also sent along with the alert. The benefit of it would have been a great way to manage alert / ticket handling. Also the custom fields would have given a better way of doing event correlation.

Question : How do we expose the custom Data fields along with the alerts of a particular single service which has been updated with lets say field like “Application Name” and “Resolver Group”
Snippet Code which is pulling host and service alerts

try {
        // On the initial itteration of the script(this mean when we don't have
        // anything in 'last_event' parameter) we are collecting all the hosts which are in
        // DOWN state and all the services which belongs to hosts in UP states.
        // On every other itteration(where we have last_event time) we are collecting all the
        // hosts and services which has been changed. The collecting time starts from the last
        // biggest time from the events(this is retrieved from last_event parameter)
        if (LAST_EVENT == 0) {
            ms.log(SOURCE + ": INITIAL RUN");
            isInitialized = false;
            hostEvents = this.getResult('/objects/hosts', {
                "filter": "host.state==1"
            });

            // Because we need to store last event time per type,
            // if we don't have any events for the current type on the Initial run
            // of the script, we are setting the current time as last event time,
            // so we'll have what to split on the next iteration
            // (this is done only on the INITIAL run for the script)
            if (hostEvents.length <= 0) {
                lastEventHost = new Date().getTime();
            }

            servicesEvents = this.getResult('/objects/services', {
                "filter": "host.state==0"
            });

            // Because we need to store last event time per type,
            // if we don't have any events for the current type on the Initial run
            // of the script, we are setting the current time as last event time,
            // so we'll have what to split on the next iteration
            // (this is done only on the INITIAL run for the script)
            if (servicesEvents.length <= 0) {
                lastEventService = new Date().getTime();
            }

        } else {
            lastEventHost = parseFloat(splittedLastEventSignature[0]);
            lastEventService = parseFloat(splittedLastEventSignature[1]);

            hostEvents = this.getResult('/objects/hosts', {
                "filter": ("host.last_state_change>" + this.getIcingaTime(lastEventHost))
            });

            servicesEvents = this.getResult('/objects/services', {
                "filter": ("service.last_state_change>" + this.getIcingaTime(lastEventService))
            });
        }

Hello All

Sorry was not able to edit the above thread. So responding below with questions

On the Web URL

http://XXX.XXX.XX.X/icingaweb2/dashboard#!/icingaweb2/monitoring/service/show?host=sgdem.xma.dc.corp.net&service=PG_DiskFree&format=json

I am getting a dump of JSON which has the custom variable that I have created. But when pulling using /objects/services API we are not getting the custom variable.

The custom variable name is u_resolverTeam which we have created in Director and attached it with service template and is populated as well

Is this a normal behavior? is there no way to expose it ?

Hi,

which script (URL) are you referring to exactly? And how is the overall architecture with ServiceNow here? Never used it myself.

Cheers,
Michael

The script is default out of box script provided in ServiceNow for integrating with iCinga2. This is part of servicenow ITOM module.

You can easily get to the script by signing up for a free servicenow account (no i m not advertising for them :stuck_out_tongue:)
Anyways attaching the whole script from the community free servcenow ITOM
theServiceNowIcingaScript.txt (25.4 KB)

The architecture is ServiceNow MidServer will be pulling alerts from iCinga Master API. So all we need to provide ServiceNow is Master’s IP address Port (5665) and API username and password. And you are done. Periodically ServiceNow will pull the alerts from iCinga.

The whole challenge is - when the alerts are pulled from the above /objects/services it doesn’t expose the custom Data Fields that I have created in Director and is part of that service template and populated with a value

Sorry I am bumping back the thread here as I am not able to figure out how to proceed. The ask here is when we pull all alerts from /objects/services API - is there no way to expose the custom data fields attached to the service that has created the alert?

iCinga do expose the custom datafields in objects/services. It is servicenow script which was not picking up the custom fields as they are not default.

But now my problem is - it exposes too many things. For example the command is exposed. The command will generally have a password for many plugins (like DBs). This is a big security issue. Can the user which is calling the restAPI be restricted somehow - so that it can pull everything from /objects/services apart from the command and var mapping? But it should pull the custom variables :crazy_face: