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

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

On an install using just the demo configurations:
Code: Select all
$ curl -u nagiosadmin:nagios -XGET ''
  "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",
        "Root Partition",
        "Swap Usage",
        "Total Processes"

Might also consider adding jq to your toolbox -- it's like sed/grep but for structured JSON:
Former Nagios employee
User avatar
Posts: 3724
Joined: Thu May 05, 2016 3:54 pm

Return to Community Support

Who is online

Users browsing this forum: No registered users and 26 guests