Display All Services for a specific contactgroup

Engage with the community of users including those using the open source solutions.
Includes Nagios Core, Plugins, and NCPA

Display All Services for a specific contactgroup

Postby DeanGabber » Tue Sep 07, 2021 5:20 am

Hi,
Hope someone can help.
I have about 10 different contactgroups to allow notifications for different aspects of the system eg: network system dev
I want to be able to list the services that are defined for a specific contactgroup
IE: Show all service belonging to the network contact group

I have tried playing around with config.cgi but no luck

I thought about writing a script that looks in the *.cfg files but that looks very difficult trying to figure out where all the contacts are defined.

Does anyone have an ideas on how I can achieve this.
Thanks in advance
Pete
DeanGabber
 
Posts: 3
Joined: Sat Aug 11, 2018 11:24 am

Re: Display All Services for a specific contactgroup

Postby mcapra » Wed Sep 08, 2021 5:06 pm

The JSON CGIs are your best friend:
https://labs.nagios.com/2014/06/19/expl ... -7-part-1/

Those CGIs should be included with any modern Nagios Core installation. To get all services associated with a contactgroup named admins:
Code: Select all
http://your.nagios.instance/cgi-bin/objectjson.cgi?query=servicelist&contactgroup=admins


On an install using just the demo configurations:
Code: Select all
$ curl -u nagiosadmin:nagios -XGET 'http://127.0.0.1:8080/cgi-bin/objectjson.cgi?query=servicelist&contactgroup=admins'
{
  "format_version": 0,
  "result": {
    "query_time": 1631139069000,
    "cgi": "objectjson.cgi",
    "user": "nagiosadmin",
    "query": "servicelist",
    "query_status": "released",
    "program_start": 1631138250000,
    "last_data_update": 1631138250000,
    "type_code": 0,
    "type_text": "Success",
    "message": ""
  },
  "data": {
    "selectors": {
      "contactgroup": "admins"
    },
    "servicelist": {
      "localhost": [
        "Current Load",
        "Current Users",
        "HTTP",
        "PING",
        "Root Partition",
        "SSH",
        "Swap Usage",
        "Total Processes"
      ]
    }
  }
}


Might also consider adding jq to your toolbox -- it's like sed/grep but for structured JSON:
https://stedolan.github.io/jq/
Former Nagios employee
https://www.mcapra.com/
User avatar
mcapra
 
Posts: 3711
Joined: Thu May 05, 2016 3:54 pm


Return to Community Support

Who is online

Users browsing this forum: Srinija544 and 25 guests