Page 1 of 1

Template for Monitoring Windows Service

Posted: Tue Nov 19, 2019 11:43 am
by Alan
Hello I am trying to find a template or config guide for how to monitor a windows service. Specifically the print spooler of server 2012 print server.I am using the ncpa-2.2.0. I am trying to add it to the ncpa.cfg file. I found this check but it does not work:

Code: Select all

./check_ncpa.py -H <HOSTNAME> -t '<your token>' -M 'services' -q 'service=spoolsv.exe'
I have also tried:

Code: Select all

./check_ncpa.py -H <HOSTNAME> -t '<your token>' -M 'services' -q 'service=C:\Windows\System32\spoolsv.exe'
I obviously changed the required info like token and hostname to the correct thing.

I have tried to change the service= to these things:
'service=spoolsv.exe'
'service=spooler'

This is whats returned when I run the ./check_ncpa.py command:
UNKNOWN: Error occurred while running the plugin. Use the verbose flag for more details.

So then I run it with -vvv and this is the full out put of the command and what I get back:

Code: Select all

[alan@Monitor libexec]$ ./check_ncpa.py -H printserver -t token -M 'services' -q 'service=C:spoolsv.exe' -vvv
Connecting to: https://printserver:5693/api/services/?token=token&check=1&service=C%3Aspoolsv.exe
An error occurred:<urlopen error [Errno -2] Name or service not known>

Re: Template for Monitoring Windows Service

Posted: Tue Nov 19, 2019 12:31 pm
by benjaminsmith
Hello Alan,

What is the exact service name of the spooler on this system? Try running the following command and post the output.

Code: Select all

./check_ncpa.py -H 10.25.14.91 -t Str0ngT0k3n -M services -q service=Spooler,status=running
spooler.png

Re: Template for Monitoring Windows Service

Posted: Wed Nov 20, 2019 12:24 pm
by Alan
Thanks for the reply. So when I use what you suggested this does come back with - OK: Spooler is running. How would I be able to add this to the ncpa.cfg file for this print server? Right now for this server I am monitoring the CPU Load, the C:\ Drive space, and Memory Usage. I tried to add this to the file.

Code: Select all

define service {
    host_name               Svr-Print01
    service_description     Print Spooler
    check_command           check_ncpa.py -H 172.16.10.31 -t CMPublic -M services -q service=Spooler,status=running
    max_check_attempts      45
    check_interval          5
    retry_interval          1
    check_period            24x7
    notification_interval   60
    notification_period     24x7
    contacts                nagiosadmin
    register                1
}
Then when i run the pre-flight check I get this error:

Code: Select all

Error: Service check command 'check_ncpa.py -H 172.16.10.31 -t Str0ngT0k3n -M services -q service=Spooler,status=running' specified in service 'Print Spooler' for host 'Svr-Print01' not defined anywhere!
Do I need to add something in teh commands.cfg?

Re: Template for Monitoring Windows Service

Posted: Wed Nov 20, 2019 2:50 pm
by Alan
So I change the check_command check_ncpa.py to check_command check_ncpa!-t and it is not working.

One thing I am trying to find out is if that service stops can I have Nagios kick off a script that would essentially delete all the contents of the PRINTER folder and restart the spooler?

Re: Template for Monitoring Windows Service

Posted: Wed Nov 20, 2019 4:35 pm
by benjaminsmith
Hello Alan,

Can you post the check command definition for check_ncpa? On my system, I have something like this and it's working.

Service Definition

Code: Select all

	service_description	Spooler
	check_period	timeperiod_24x7
	check_command	check_ncpa!-t password -M services -q service=Spooler,status=running!
Command Definition

Code: Select all

define command {
	command_name	check_ncpa
	command_line	$USER1$/check_ncpa.py -H $HOSTADDRESS$ $ARG1$
	}
One thing I am trying to find out is if that service stops can I have Nagios kick off a script that would essentially delete all the contents of the PRINTER folder and restart the spooler?
Yes. You can setup Naigos to fire an event handler (script) whenever a state change occurs.

See: Event Handlers

Re: Template for Monitoring Windows Service

Posted: Thu Nov 21, 2019 2:20 pm
by Alan
Hi Benjamin

This is in the ncpa.cfg file

Code: Select all

define service {
    host_name               Svr-Print01
    service_description     Print Spooler
    check_command           check_ncpa!-t -H Svr-Print01 -t token -M services -q service=Spooler,status=running
    max_check_attempts      5
    check_interval          5
    retry_interval          1
    check_period            24x7
    notification_interval   60
    notification_period     24x7
    contact_groups               admins
    register                1
}
So this is in the commands.cfg file

Code: Select all

define command {
    command_name    check_ncpa
    command_line    $USER1$/check_ncpa.py -H $HOSTADDRESS$ $ARG1$
}
I hope this is the info you are wanting? Thanks for the Event Handlers I will read through it and see if I can get it to work. I have a side question if we ever move to Nagios I will all these setting that I am configuring move over as well or would I need to reconfigure everything?

Re: Template for Monitoring Windows Service

Posted: Thu Nov 21, 2019 2:51 pm
by mbellerue
Let's change your check_command in ncpa.cfg once more.

Code: Select all

check_command           check_ncpa!-t token -M services -q service=Spooler,status=running
Try that out and see if it works.

Also, if you move to Nagios XI, there is a tool to import Core configuration files.

Re: Template for Monitoring Windows Service

Posted: Thu Nov 21, 2019 3:19 pm
by Alan
I totally apologize. I noticed on the previous reply I said

" So I change the check_command check_ncpa.py to check_command check_ncpa!-t and it is not working. "

Ya I meant to say it is working. Sorry about that. It is monitoring the spooler now and it does send me a email if the spooler stops.

Re: Template for Monitoring Windows Service

Posted: Thu Nov 21, 2019 3:34 pm
by mbellerue
Oh, perfect! Does that solve the issue entirely, or are there still things that need to be fixed? I can just close this thread if all is well now.

Re: Template for Monitoring Windows Service

Posted: Thu Nov 21, 2019 4:12 pm
by Alan
I think that is it. I will look at the Event Handlers page and see if I can get it to work. If for some reason I cannot I will most likely open a new thread. Thanks for all your help with this. Have a great day.