Restricting ServiceNow to Pull Service Alerts of Certain Host.Groups


ServiceNow default collector use the following lines to pull the information from ICINGA

//If the poll is first time

                hostEvents = this.getResult('/objects/hosts', {
                    "filter": "host.state==1"

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

// Pulling events of delta time

                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))

The full script I have posted earlier in ServiceNow Event Management Integration with iCinga2

Now my requirement is I want to restrict ServiceNow to pull events only from certain hostgroup. This was showed to us by icinga support via a ticket. But somehow we are not able to incorporate the restriction along with the above scripts. Any help will be really helpful

What we were told by icinga support was instead of the /object/host or /object/service

Use the following

/objects/hosts' -d '{ "filter": "group in host.groups && host.state==1", "filter_vars": { "group": "XXX-GroupHost-MB-ALL" }, "pretty": true }'

/objects/services' -d '{ "filter": "group in host.groups && host.state==0", "filter_vars": { "group": "XXX-GroupHost-MB-ALL" }, "pretty": true }' 

/objects/hosts' -d '{ "filter": "group in host.groups && host.last_state_change >" + this.getIcingaTime(lastEventHost), "filter_vars": { "group": "XXX-GroupHost-MB-ALL" }, "pretty": true }'

/objects/services' -d '{ "filter": "group in host.groups && service.last_state_change>" + this.getIcingaTime(lastEventService), "filter_vars": { "group": "XXX-GroupHost-MB-ALL" }, "pretty": true }'

But somehow when we are not able to use it in the servicenow connector script.

Any help or direction will be nice. This will really help in multi-tenant models or if a company have 2 different ServiceNow and they want to create tickets for specifics only

try to debug your api calls using curl, make sure that the group name is correct

this one worked for me, exchange user and password:

curl -k -s -S -i -u 'root:icinga' -H 'Accept: application/json' \
 -H 'X-HTTP-Method-Override: GET' -X POST \
 'https://localhost:5665/v1/objects/hosts' \
 -d '{ "filter": "group in host.groups && host.state==1", "filter_vars": { "group": "test-instances" }, "pretty": true }'

if the problem is not the query but the way the script handles it use this syntax to define the filter:
“The double quotes need to be escaped with a preceeding backslash:”

-d '{ "type": "Host", "filter": "\"linux-servers\" in host.groups && host.state==1" }'

The query is fine. Can do it on the server. But servicenow is not able to call this. Servicenow code posted in the first post