Obtaining configuration

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
tcjr2
Posts: 9
Joined: Thu Feb 01, 2018 4:05 pm

Obtaining configuration

Post by tcjr2 »

What is the easiest way to obtain a report of the current services that includes:
1) service name
2) service description
3) service state (i.e., active or not)
4) associated hosts
5) notification contacts
6) other info is helpful but not necessary

I've looked in the objects.cache file and all the info I need is there but each service is defined for each host so with the 65 services we have there are 360 "define service" entries in the file.

Thanks for any help -- Tom
kyang

Re: Obtaining configuration

Post by kyang »

Hey Tom,

You could grep for that information. I'll try to work on something when I can.

I'm not exactly sure of the fields you wanted from the objects.cache. With the list, you provided up above?

Could you give the exact names of each field from the objects.cache file?

Code: Select all

service name --> service description
service description -- xx
service state --> active_checks_enabled
associated hosts --> host_name
notification contacts --> contacts
tcjr2
Posts: 9
Joined: Thu Feb 01, 2018 4:05 pm

Re: Obtaining configuration

Post by tcjr2 »

if you could give me these 4 fields (service_description|host_name|contacts|contact_groups), separated by the pipe char (|) for each "define service" that would be perfect. Thanks very much for your help -- Tom
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Obtaining configuration

Post by mcapra »

Here's a nice neat new-line delimited version of that thing:

Code: Select all

[root@capra_nag services]# sed -e '/define service/,/}/!d' /usr/local/nagios/var/objects.cache | grep 'host_name\|service_description\|contact_groups\|contacts' | sed 's/host_name/\n\thost_name/'
        host_name       PRODDELPHISCRIPTS
        service_description     DataMart
        contact_groups  admins

        host_name       PRODDELPHISCRIPTS
        service_description     Graylog
        contact_groups  admins

        host_name       PRODDELPHISCRIPTS
        service_description     Logstash
        contact_groups  admins

        host_name       PRODDELPHISCRIPTS
        service_description     Process Monitor
        contact_groups  admins

        host_name       PRODHERMES1
        service_description     Hermes Front-end on 7777
        contacts        nagiosadmin
        contact_groups  admins

        host_name       PRODHERMES2
        service_description     Hermes Front-end on 7777
        contacts        nagiosadmin
        contact_groups  admins

        host_name       PRODHERMES3
        service_description     Hermes Front-end on 7777
        contacts        nagiosadmin
        contact_groups  admins
It's worth mentioning that objects.cache only contains the configuration directives that are absolutely necessary; IE it won't "auto fill" unecessary directives. If there's no contacts or contact_groups assigned/inherited (bequeathed?) to a service, they won't show up.

The first 4 results only have a contact_groups directive in their config file. The last 4 results have both a contacts and contact_groups directive in their config file. You could do more clever things with sed than I have to get it into CSV (or pipe-delimited format) I imagine.
Former Nagios employee
https://www.mcapra.com/
kyang

Re: Obtaining configuration

Post by kyang »

Thanks for the help @mcapra!

This is definitely nice.

tcjr2, Does this answer your question?
tcjr2
Posts: 9
Joined: Thu Feb 01, 2018 4:05 pm

Re: Obtaining configuration

Post by tcjr2 »

Yes it is exactly what I needed. Thanks for the quick turnaround -- Tom
kyang

Re: Obtaining configuration

Post by kyang »

Yes, thanks @mcapra!

tcjr2, Did you have any more questions or are we okay to lock this up?
Locked