Page 1 of 1

Exporting Nagios info - objects.config

Posted: Fri May 03, 2024 11:25 am
by logisbk
I need to gather all host and service info from Nagios specifically hosts, host groups, contacts, contact groups - and the same for services. I also need the inherited associations, ie an inherited contact from a host template.

My understanding is that all of this info is in the objects.config file, and I have pulled that into an Excel sheet. I need to bring each field into it's own column so I can filter it, and in the file each field is a separate row, so the spreadsheet has literally hundreds of thousand of rows. I've tried a variety of Excel formulas, though I am no Excel expert. A simple filter for example to filter column B for host_name and copy all the host names in column C to a new sheet, do the same for contacts, etc could work, but the issue is that some services/hosts don't have that defined so then it's thrown off. I ran into the same issue with my other formulas.

I found this post which is promising, but when I attempt to run it, I get an unterminated string, syntax error. Command below:

Code: Select all

awk 'BEGIN{print "host_name,hostgroups,contacts,contact_groups"} /host_name/{v1=$2} /hostgroups/{v2=","$2} /contacts/{v3=","$2} /contact_groups/{v4=","$2} /}/{print v1","v2","v3,"v4; v1=v2=v3=v4""}' objects.txt > objectexport2.csv
Anyone have thoughts on the best way to do this?

Re: Exporting Nagios info - objects.config

Posted: Fri May 03, 2024 3:17 pm
by jmichaelson
Looks like you have an extraneous " character near the end of the command after v3=v4, right here:

v1=v2=v3=v4""}'

Re: Exporting Nagios info - objects.config

Posted: Mon May 06, 2024 10:11 am
by logisbk
Thanks Jason. I was able to get it to work after removing the 'hostgroups' as that doesn't appear to be a field in the file.

Code: Select all

awk 'BEGIN{print "host_name,contacts,contact_groups"} /host_name/{v1=$2} /contacts/{v2=$2} /contact_groups/{v3=$2} /}/{print v1","v2","v3; v1=v2=v3=""}' objects.txt > objectexport3.csv

Re: Exporting Nagios info - objects.config

Posted: Mon May 06, 2024 11:07 am
by logisbk
Oh and I realized I missed a " which is why the extraneous one was at the end, I missed one after the v3

Code: Select all

/{print v1","v2","v3","v4; v1=v2=v3=v4""}'