Using NRPE for windows server

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.

Re: Using NRPE for windows server

Postby npolovenko » Mon Jan 08, 2018 1:22 pm

@skypete, Can you upload /usr/local/nagios/etc/nagios.cfg file as well as the new .cfg file that you created with the configs that I gave you?

could you please post a link of samples of check_nrpe services thanks.

They're in these articles https://support.nagios.com/kb/category.php?id=186
For example, if you're interested in measuring the memory usage you'd open a Memory Checks article. Then you'd scroll down till you see NSClient++ via check_nrpe.
You'd see this command:
Code: Select all
./check_nrpe -H 10.25.14.10 -c check_memory -a 'warn=free<20%' 'crit=free<10%'

Then you'd just copy and paste the service definition inside the .cfg file you created earlier.
Code: Select all
define service {
    host_name                 HostName
    service_description      MemoryCheck
    check_command          check_nrpe!check_memory!-a 'warn= uptime > 1d' 'crit= uptime > 1d'
    max_check_attempts      5
    check_interval          5
    retry_interval          1
    check_period            24x7
    notification_interval   60
    notification_period     24x7
    contacts                nagiosadmin
}

That's it. Restart nagios and the new service check should show up in the web interface:
Code: Select all
service nagios restart


If you're unsure why i'm using ! in check_command that's because Nagios will pass this to the template that we defined earlier:

Code: Select all
define command {
   command_name                             check_nrpe
   command_line                             $USER1$/check_nrpe -H $HOSTADDRESS$ -t 30 -c $ARG1$ $ARG2$
}

check_memory will replace $ARG1$, and -a 'warn= uptime > 1d' 'crit= uptime > 1d' will replace $ARG2$. So ! is just a delimiter to separate $ARG1$ and $ARG2$ .

Take a look at this article if you need more clarification on how command work in Nagios:
https://assets.nagios.com/downloads/nag ... ml#command
User avatar
npolovenko
Support Tech
 
Posts: 1315
Joined: Mon May 15, 2017 5:00 pm

Re: Using NRPE for windows server

Postby skypete » Wed Jan 31, 2018 10:26 am

npolovenko wrote:@skypete, Can you upload /usr/local/nagios/etc/nagios.cfg file as well as the new .cfg file that you created with the configs that I gave you?

could you please post a link of samples of check_nrpe services thanks.

They're in these articles https://support.nagios.com/kb/category.php?id=186
For example, if you're interested in measuring the memory usage you'd open a Memory Checks article. Then you'd scroll down till you see NSClient++ via check_nrpe.
You'd see this command:
Code: Select all
./check_nrpe -H 10.25.14.10 -c check_memory -a 'warn=free<20%' 'crit=free<10%'

Then you'd just copy and paste the service definition inside the .cfg file you created earlier.
Code: Select all
define service {
    host_name                 HostName
    service_description      MemoryCheck
    check_command          check_nrpe!check_memory!-a 'warn= uptime > 1d' 'crit= uptime > 1d'
    max_check_attempts      5
    check_interval          5
    retry_interval          1
    check_period            24x7
    notification_interval   60
    notification_period     24x7
    contacts                nagiosadmin
}

That's it. Restart nagios and the new service check should show up in the web interface:
Code: Select all
service nagios restart


If you're unsure why i'm using ! in check_command that's because Nagios will pass this to the template that we defined earlier:

Code: Select all
define command {
   command_name                             check_nrpe
   command_line                             $USER1$/check_nrpe -H $HOSTADDRESS$ -t 30 -c $ARG1$ $ARG2$
}

check_memory will replace $ARG1$, and -a 'warn= uptime > 1d' 'crit= uptime > 1d' will replace $ARG2$. So ! is just a delimiter to separate $ARG1$ and $ARG2$ .

Take a look at this article if you need more clarification on how command work in Nagios:
https://assets.nagios.com/downloads/nag ... ml#command




Hi all that worked and thanks for that, I wanted to ask I am trying some scripts so my first attempt is to restart services on windows servers. could you give me some pointers on how to run scripts from a nagios core server? I read your article on how to restart windows services would that work with the nagios core version? if not could you please point me in the right direction thanks so much.
skypete
 
Posts: 41
Joined: Sat Dec 02, 2017 11:44 pm

Re: Using NRPE for windows server

Postby npolovenko » Wed Jan 31, 2018 4:45 pm

@skypete, Yes, it'll work. But of course, the process of creating an event handler on Nagios core is different. That is if you want to have Nagios restart some service on a windows server automatically when a certain check returns critical. Otherwise, you'll just follow this tutorial:
https://assets.nagios.com/downloads/nag ... ios-XI.pdf
And you'll be able to remotely restart services with this command:
Code: Select all
/usr/local/nagios/libexec/check_nrpe -H windows_server_ip_address -p 5666 -c restart_service -a service_name

If you want to go further to create an event handler, use this tutorial:
https://assets.nagios.com/downloads/nag ... dlers.html
User avatar
npolovenko
Support Tech
 
Posts: 1315
Joined: Mon May 15, 2017 5:00 pm

Re: Using NRPE for windows server

Postby skypete » Thu Feb 01, 2018 11:49 am

HI From the event handler document where do the commands go exaclty such as the define service and defind command.
skypete
 
Posts: 41
Joined: Sat Dec 02, 2017 11:44 pm

Re: Using NRPE for windows server

Postby npolovenko » Thu Feb 01, 2018 2:56 pm

1) From the previous step:
Code: Select all
define service {
    host_name                 HostName
    service_description      MemoryCheck
    check_command          check_nrpe!check_memory!-a 'warn= uptime > 1d' 'crit= uptime > 1d'
    max_check_attempts      5
      event_handler           restart-service
    check_interval          5
    retry_interval          1
    check_period            24x7
    notification_interval   60
    notification_period     24x7
    contacts                nagiosadmin
}


2) nano /usr/local/nagios/libexec/restart_service.sh
Code: Select all
#!/bin/sh
case "$1" in
OK)
;;
WARNING)
;;
UNKNOWN)
;;
CRITICAL)
/usr/local/nagios/libexec/check_nrpe -H "$2" -p 5666 -c restart_service -a "$3"
;;
esac
exit 0

3.
Code: Select all
chown apache:nagios /usr/local/nagios/libexec/restart_service.sh
chmod 775 /usr/local/nagios/libexec/restart_service.sh

4.
in commands.cfg:
Code: Select all
define command {
    command_name     restart-service
    command_line    $USER1$/restart_service.sh $SERVICESTATE$ $HOSTADDRESS$ $_SERVICESERVICE$T$
}

5.
Code: Select all
service nagios restart


That should do it.
User avatar
npolovenko
Support Tech
 
Posts: 1315
Joined: Mon May 15, 2017 5:00 pm

Re: Using NRPE for windows server

Postby skypete » Thu Feb 08, 2018 10:54 am

hi will this service command check_nrpe!check_memory!-a 'warn= uptime > 1d' 'crit= uptime > 1d'
WIll this restart all the services if they happen to stop on the window server? sorry little confused

also when i run this command i get and invalid user: apache:nagios

chown apache:nagios /usr/local/nagios/libexec/restart_service.sh
skypete
 
Posts: 41
Joined: Sat Dec 02, 2017 11:44 pm

Re: Using NRPE for windows server

Postby npolovenko » Thu Feb 08, 2018 12:09 pm

@skypete, I forgot to update the service check. So this command:
Code: Select all
check_command          check_nrpe!check_process!process=spoolsv.exe!show-all

Checks if the process "spoolsv.exe" is running on the windows server, and then it passes states(OK, WARNING, UNKNOWN or Critical) to the restart_service.sh event handlers script. The script determines if the state is critical and send a remote command to restart the service. So, the correct service definition is below(replace spoolsv.exe with the name of the service that you want to monitor):

Code: Select all
define service {
    host_name                 HostName
    service_description      Process Check
    check_command          check_nrpe!check_process!process=spoolsv.exe!show-all
    max_check_attempts      5
      event_handler           restart-service
    check_interval          5
    retry_interval          1
    check_period            24x7
    notification_interval   60
    notification_period     24x7
    contacts                nagiosadmin
}


also when i run this command i get and invalid user: apache:nagios

chown apache:nagios /usr/local/nagios/libexec/restart_service.sh

Try
Code: Select all
chown apache.nagios /usr/local/nagios/libexec/restart_service.sh
User avatar
npolovenko
Support Tech
 
Posts: 1315
Joined: Mon May 15, 2017 5:00 pm

Re: Using NRPE for windows server

Postby skypete » Thu Feb 08, 2018 1:39 pm

Sorry little confused will this command restart all services that stops or just one service that stops. looking to restart all services if any should stop thanks and the chown apache.nagios /usr/local/nagios/libexec/restart_service.sh still did not work thanks for you help




npolovenko wrote:@skypete, I forgot to update the service check. So this command:
Code: Select all
check_command          check_nrpe!check_process!process=spoolsv.exe!show-all

Checks if the process "spoolsv.exe" is running on the windows server, and then it passes states(OK, WARNING, UNKNOWN or Critical) to the restart_service.sh event handlers script. The script determines if the state is critical and send a remote command to restart the service. So, the correct service definition is below(replace spoolsv.exe with the name of the service that you want to monitor):

Code: Select all
define service {
    host_name                 HostName
    service_description      Process Check
    check_command          check_nrpe!check_process!process=spoolsv.exe!show-all
    max_check_attempts      5
      event_handler           restart-service
    check_interval          5
    retry_interval          1
    check_period            24x7
    notification_interval   60
    notification_period     24x7
    contacts                nagiosadmin
}


also when i run this command i get and invalid user: apache:nagios

chown apache:nagios /usr/local/nagios/libexec/restart_service.sh

Try
Code: Select all
chown apache.nagios /usr/local/nagios/libexec/restart_service.sh
skypete
 
Posts: 41
Joined: Sat Dec 02, 2017 11:44 pm

Re: Using NRPE for windows server

Postby kyang » Thu Feb 08, 2018 2:12 pm

skypete
Sorry little confused will this command restart all services that stops or just one service that stops. looking to restart all services if any should stop thanks and the chown apache.nagios /usr/local/nagios/libexec/restart_service.sh still did not work thanks for you help


This script only restarts "1" service that you specify. If you wanted to restart all services, then you would need to create an individual service and check_command for all of the services you would like to restart.

Just as you did before for this service.
Code: Select all
check_command          check_nrpe!check_process!process=spoolsv.exe!show-all


Code: Select all
define service {
    host_name                 HostName
    service_description      Process Check
    check_command          check_nrpe!check_process!process=spoolsv.exe!show-all
    max_check_attempts      5
      event_handler           restart-service
    check_interval          5
    retry_interval          1
    check_period            24x7
    notification_interval   60
    notification_period     24x7
    contacts                nagiosadmin
}
Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
kyang
Support Tech
 
Posts: 1505
Joined: Tue Jul 25, 2017 3:35 pm

Re: Using NRPE for windows server

Postby skypete » Thu Feb 08, 2018 4:34 pm

Ok I have tried it its seems to not work, would I need to add any entries in the commands.cfg for instance if i want to restart a service like DHCP. How would i know if the process starts back up when stopped? I did tried to stop it to see if would start it back up and it did not. Wanted to mentioned would I need to add in my ini file where it says allow arguments = true or is it ok from the command below? Could you please explain better truly sorry.

<command>=<script> <arguments>
[/settings/external scripts/scripts]
restart_service = scripts\restart_service.bat "$ARG1$"
check_windows_time=scripts\check_windows_time.bat $ARG1$
; TODO
Last edited by skypete on Thu Feb 08, 2018 5:05 pm, edited 2 times in total.
skypete
 
Posts: 41
Joined: Sat Dec 02, 2017 11:44 pm

PreviousNext

Return to Nagios Core

Who is online

Users browsing this forum: No registered users and 32 guests