Command to check no of hosts and services

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
DOkuwa
Posts: 114
Joined: Tue Aug 15, 2017 3:54 pm

Command to check no of hosts and services

Post by DOkuwa »

All ,

How can I find the no of hosts and services by command line on a unix machine ( red hat and Ubuntu)
on both Nagios Core and XI
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Command to check no of hosts and services

Post by mcapra »

Quick and dirty grep commands below.

Total number of hosts being checked by Nagios:

Code: Select all

grep -w -c hoststatus /usr/local/nagios/var/status.dat
Total number of services being checked by Nagios:

Code: Select all

grep -w -c servicestatus /usr/local/nagios/var/status.dat
Former Nagios employee
https://www.mcapra.com/
DOkuwa
Posts: 114
Joined: Tue Aug 15, 2017 3:54 pm

Re: Command to check no of hosts and services

Post by DOkuwa »

Thanks
I cant find status.dat but status.log
is this the same
kyang

Re: Command to check no of hosts and services

Post by kyang »

Thanks @mcapra!

A status.dat file is created when Nagios is started, and deleted when Nagios is stopped --> is Nagios started?

What is in the status.log file? Does it contain this information?
This is the file that Nagios uses to store the current status, comment, and downtime information.
What the path to that status.log file? --> Is it here /usr/local/nagios/var

Otherwise did mcapra's command work for you? Change status.dat to status.log.
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Command to check no of hosts and services

Post by mcapra »

Maybe? I don't recognize that file. Is this a Nagios Core 4 machine?

Give this a try:

Code: Select all

grep status_file /usr/local/nagios/etc/nagios.cfg
Which should output something like this:

Code: Select all

[root@capra_nag data_preparation]# grep status_file /usr/local/nagios/etc/nagios.cfg
status_file=/usr/local/nagios/var/status.dat
You'll want to point the grep command at wherever status_file is pointing. status.dat is what Nagios Core typically writes to when representing the status of your infrastructure (whats up, what's down, what check attempt, etc). If you're running mklivestatus or some other NEB module, that may impact where your status information is written.

Also as @kyang pointed out, make sure the Nagios daemon is running.
Former Nagios employee
https://www.mcapra.com/
DOkuwa
Posts: 114
Joined: Tue Aug 15, 2017 3:54 pm

Re: Command to check no of hosts and services

Post by DOkuwa »

both
on Nagios Core and Nagios XI
two different boxes
I saw this on the Nagios core machine on Ubuntu

:/usr/local/nagios/var# grep status_file /usr/local/nagios/etc/nagios.cfg
status_file=/usr/local/nagios/var/status.log
/usr/local/nagios/var# grep -w -c hoststatus status.log
430

but on the XI machine on red hat linux
grep status_file /usr/local/nagios/etc/nagios.cfg
status_file=/usr/local/nagios/var/status.log

# grep -w -c servicestatus /usr/local/nagios/var/status.dat
2355

I think they are the same files both status.log and status.dat
kyang

Re: Command to check no of hosts and services

Post by kyang »

Are the commands working as expected? If it looks to be the same as a status.dat file as in --> status.log shows current status information.

From what @mcapra gave you. Is this what you wanted to see from the command line?

Did you have any more questions or we are okay to close this thread?
DOkuwa
Posts: 114
Joined: Tue Aug 15, 2017 3:54 pm

Re: Command to check no of hosts and services

Post by DOkuwa »

Please close the thread
kyang

Re: Command to check no of hosts and services

Post by kyang »

Sounds great! I'll be closing this topic.

If you have any more questions, feel free to create another thread!

Thank you for using the Nagios Support Forum!
Locked