Page 1 of 1

Obtaining configuration

Posted: Fri Feb 09, 2018 2:06 pm
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

Re: Obtaining configuration

Posted: Fri Feb 09, 2018 3:26 pm
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

Re: Obtaining configuration

Posted: Sat Feb 10, 2018 8:35 pm
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

Re: Obtaining configuration

Posted: Mon Feb 12, 2018 10:13 am
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.

Re: Obtaining configuration

Posted: Mon Feb 12, 2018 10:50 am
by kyang
Thanks for the help @mcapra!

This is definitely nice.

tcjr2, Does this answer your question?

Re: Obtaining configuration

Posted: Tue Feb 13, 2018 9:13 am
by tcjr2
Yes it is exactly what I needed. Thanks for the quick turnaround -- Tom

Re: Obtaining configuration

Posted: Tue Feb 13, 2018 10:04 am
by kyang
Yes, thanks @mcapra!

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