Template for Monitoring Windows Service

An open discussion forum for obtaining help with Nagios Core. Nagios Core users of all experience levels are welcome here. Subforum have been created for the discussion of Nagios Core and Nagios Plugin development.

NOTE: The SourceForge.net mailing lists have been deprecated in favor of this forum in order to expedite support and provide additional features not available on the old mailing list.

Template for Monitoring Windows Service

Postby Alan » Tue Nov 19, 2019 11:43 am

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>
Alan
 
Posts: 54
Joined: Wed Aug 21, 2019 4:14 pm

Re: Template for Monitoring Windows Service

Postby benjaminsmith » Tue Nov 19, 2019 12:31 pm

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
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
benjaminsmith
 
Posts: 1992
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: Template for Monitoring Windows Service

Postby Alan » Wed Nov 20, 2019 12:24 pm

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?
Alan
 
Posts: 54
Joined: Wed Aug 21, 2019 4:14 pm

Re: Template for Monitoring Windows Service

Postby Alan » Wed Nov 20, 2019 2:50 pm

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?
Alan
 
Posts: 54
Joined: Wed Aug 21, 2019 4:14 pm

Re: Template for Monitoring Windows Service

Postby benjaminsmith » Wed Nov 20, 2019 4:35 pm

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
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
benjaminsmith
 
Posts: 1992
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: Template for Monitoring Windows Service

Postby Alan » Thu Nov 21, 2019 2:20 pm

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?
Alan
 
Posts: 54
Joined: Wed Aug 21, 2019 4:14 pm

Re: Template for Monitoring Windows Service

Postby mbellerue » Thu Nov 21, 2019 2:51 pm

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.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
mbellerue
 
Posts: 940
Joined: Fri Jul 12, 2019 11:10 am

Re: Template for Monitoring Windows Service

Postby Alan » Thu Nov 21, 2019 3:19 pm

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.
Alan
 
Posts: 54
Joined: Wed Aug 21, 2019 4:14 pm

Re: Template for Monitoring Windows Service

Postby mbellerue » Thu Nov 21, 2019 3:34 pm

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.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
mbellerue
 
Posts: 940
Joined: Fri Jul 12, 2019 11:10 am

Re: Template for Monitoring Windows Service

Postby Alan » Thu Nov 21, 2019 4:12 pm

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.
Alan
 
Posts: 54
Joined: Wed Aug 21, 2019 4:14 pm


Return to Nagios Core

Who is online

Users browsing this forum: adrianothefrench and 33 guests