Restarting Linux Service With NRPE Problem

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
andresfvs
Posts: 7
Joined: Wed Apr 20, 2016 10:24 am

Restarting Linux Service With NRPE Problem

Post by andresfvs »

Hi, guys...

First, my environment:

Nagios Server CentOS 6.7
Remote Host: CentOS Linux 7.2.1511

Something special in the environment? Nothing... same plugins...

My problem is that i am following the "Restarting Linux Service With NRPE" Nagios guide... but when i try to restart any service, it doesn't work... dont restart...

By example... i'm trying to restart ntpd service like in the guide... when i exec the command it happens nothing... and when i exec locally the command, it shows the message and doesn't restart the ntpd command...

/usr/local/nagios/libexec/check_nrpe -H <Remote IP> -t 30 -c check_init_service -a 'ntpd'
● ntpd.service - Network Time Service
Loaded: loaded (/usr/lib/systemd/system/ntpd.service; disabled; vendor preset: disabled)
Active: inactive (dead) since Tue 2016-06-14 05:51:17 PDT; 17min ago
Process: 40312 ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 40313 (code=exited, status=0/SUCCESS)

Jun 14 05:38:49 portal ntpd[40313]: Listening on routing socket on fd #25 for interface updates
Jun 14 05:39:06 portal ntpd[40313]: 0.0.0.0 c016 06 restart
Jun 14 05:39:06 portal ntpd[40313]: 0.0.0.0 c012 02 freq_set kernel 11.091 PPM
Jun 14 05:39:08 portal ntpd[40313]: 0.0.0.0 c61c 0c clock_step -2.835776 s
Jun 14 05:39:05 portal ntpd[40313]: 0.0.0.0 c614 04 freq_mode
Jun 14 05:39:06 portal ntpd[40313]: 0.0.0.0 c618 08 no_sys_peer
Jun 14 05:40:17 portal ntpd[40313]: 0.0.0.0 c628 08 no_sys_peer
Jun 14 05:51:15 portal ntpd[40313]: ntpd exiting on signal 15
Jun 14 05:51:15 portal systemd[1]: Stopping Network Time Service...
Jun 14 05:51:17 portal systemd[1]: Stopped Ne

and is the same with the httpd command...

/usr/local/nagios/libexec/check_nrpe -H <Remote IP> -t 30 -c check_init_service -a 'httpd'
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2016-06-14 05:40:24 PDT; 49min ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 40384 (httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
CGroup: /system.slice/httpd.service
├─40384 /usr/sbin/httpd -DFOREGROUND
├─40431 /usr/sbin/httpd -DFOREGROUND
├─40432 /usr/sbin/httpd -DFOREGROUND
├─40433 /usr/sbin/httpd -DFOREGROUND
├─40434 /usr/sbin/httpd -DFOREGROUND
└─40435 /usr/sbin/httpd -DFOREGROUND

Jun 14 05:39:19 portal systemd[1]: Starting The Apache HTTP Server...
Jun 14 05:40:21 portal httpd[40384]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::20c:29ff:fe3e:dd42. Set the 'ServerName' directive globally to suppress this message

All the remote hosts services are being monitored... it works excellent!!! And i have a windows machine with NSClient and it restarts the services... but with linux, i can't do it work!!!

Thank you by your help!!!
andresfvs
Posts: 7
Joined: Wed Apr 20, 2016 10:24 am

Re: Restarting Linux Service With NRPE Problem

Post by andresfvs »

Sorry, i saw that the httpd service was running...

Here is the message when the httpd service is down...

/usr/local/nagios/libexec/check_nrpe -H <Remote IP> -t 30 -c check_init_service -a 'httpd'
OUTPUT: ● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: inactive (dead)
Docs: man:httpd(8)
man:apachectl(8)

Jun 13 13:25:08 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...
Jun 13 13:25:08 localhost.localdomain httpd[9153]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
Jun 13 13:25:08 localhost.localdomain systemd[1]: Started The Apache HTTP Server.
Jun 13 15:06:56 localhost.localdomain systemd[1]: Stopping The Apache HTTP Server...
Jun 13 15:06:57 localhost.localdomain systemd[1]: Stopped The Apache HTTP Server.
Jun 14 05:39:19 portal systemd[1]: Starting The Apache HTTP Server...
Jun 14 05:40:21 portal httpd[40384]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::20c:29ff:fe3e:dd42. Set the 'Server
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Restarting Linux Service With NRPE Problem

Post by rkennedy »

and when i exec locally the command, it shows the message and doesn't restart the ntpd command...
Can you show us the script you're executing locally and how you have it saved? Also, please show us your NRPE configuration file on the client side.
Former Nagios Employee
andresfvs
Posts: 7
Joined: Wed Apr 20, 2016 10:24 am

Re: Restarting Linux Service With NRPE Problem

Post by andresfvs »

Good afternoon, guys... My problem is that nagios doesn't restart automatically my (httpd, sshd, ntdp, etc) service...

My command is inside the nrpe.cfg file... and i'm using this Nagios guide: https://assets.nagios.com/downloads/nag ... h_NRPE.pdf

This is my nrpe.cfg at remote host. All that other information, was commented.

------------------------------------------------------------------
log_facility=daemon

pid_file=/var/run/nrpe.pid

server_port=5666

nrpe_user=nagios

nrpe_group=nagios

allowed_hosts=127.0.0.1,<Remote IP>

dont_blame_nrpe=1

debug=0

command_timeout=60

connection_timeout=300

include_dir=/usr/local/nagios/etc/nrpe

command[runcmd]=sudo service $ARG1$ restart
---------------------------------------------------------------------------------

The script that i am exec is:

COMMAND: /usr/local/nagios/libexec/check_nrpe -H <Remote IP> -t 30 -c check_init_service -a 'httpd'

The answer is:

OUTPUT: httpd is stopped

The variable definition is:

Variable name:_SERVICE
Variable definition: httpd

Check settings:

Event Handler Enabled: on
Event Handler: service_restart_linux

service_restart_linux code: (here is the runcmd script that was defined in nrpe.cfg):
-----------------------------------------------------------------------------------
#!/bin/sh
# Event Handler for Restarting Linux/BSD/Windows Services
case "$1" in
OK)
;;
WARNING)
;;
UNKNOWN)
;;
CRITICAL)

/usr/local/nagios/libexec/check_nrpe -H "$2" -p 5666 -c runcmd -a "$3"
;;
esac

exit 0
------------------------------------------------------------------------------------------

Thank you
User avatar
tgriep
Madmin
Posts: 9190
Joined: Thu Oct 30, 2014 9:02 am

Re: Restarting Linux Service With NRPE Problem

Post by tgriep »

In the document, you have to edit the /etc/sudoers file on the remote system so the NRPE agent has sufficient permissions to restart those daemons, have you done that?
Be sure to check out our Knowledgebase for helpful articles and solutions!
andresfvs
Posts: 7
Joined: Wed Apr 20, 2016 10:24 am

Re: Restarting Linux Service With NRPE Problem

Post by andresfvs »

Good morning, guys... Yes, i modified the sudoers file... here the uncommented lines of sudoers file...

-------------------------------------------------------------------------

Defaults visiblepw

Defaults always_set_home

Defaults env_reset
Defaults env_keep = "COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR LS_COLORS"
Defaults env_keep += "MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE"
Defaults env_keep += "LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES"
Defaults env_keep += "LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE"
Defaults env_keep += "LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY"

Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin

root ALL=(ALL) ALL

#Defaults:nagios !requiretty
nagios ALL=NOPASSWD: /usr/local/nagios/libexec/check_init_service
User avatar
eloyd
Cool Title Here
Posts: 2190
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: Restarting Linux Service With NRPE Problem

Post by eloyd »

This line:

Code: Select all

#Defaults:nagios !requiretty
Should be uncommented:

Code: Select all

Defaults:nagios !requiretty
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Restarting Linux Service With NRPE Problem

Post by rkennedy »

Thanks @eloyd!

@andresfvs - let us know if that helps.
Former Nagios Employee
Locked