Page 1 of 1

Problem executing Handler Script

Posted: Thu Nov 23, 2017 9:45 am
by KRVS
Hello,

I want to make a handle script that send me a notification with the top processes everytime to the CPU changes the status.

I have a script to saves the top cpu processes in a /temp/ file and shows it:

Code: Select all

#!/bin/bash
rm /tmp/checktopcpu.txt
date=$(date)
echo -e "$date" >> /tmp/checktopcpu.txt
ps -eo pcpu,args --sort=-%cpu|head >> /tmp/checktopcpu.txt
echo -e "\n" >> /tmp/checktopcpu.txt
cat /tmp/checktopcpu.txt
I modified the sudoers file to execute it without password, and create the command in nrpe.conf

Code: Select all

command[check_topcpu_linux]=/usr/local/nagios/libexec/check_topcpu_linux
In that point all it's working correctly, If I execute it in my nagios sever:

Code: Select all

[root@localhost libexec]# ./check_nrpe -H XXX.XXX.XXX.XXX -t 60 -p 5666 -c check_topcpu_linux
Thu Nov 23 15:37:50 CET 2017
%CPU COMMAND
 0.0 /sbin/init
 0.0 [kthreadd]
 0.0 [ksoftirqd/0]
 0.0 [kworker/0:0]
 0.0 [kworker/0:0H]
 0.0 [rcu_sched]
 0.0 [rcu_bh]
 0.0 [migration/0]
 0.0 [watchdog/0]
After I create the command in nagios:

Code: Select all

define command {
       command_name                  		check_topcpu_linux
       command_line                  		$USER1$/check_nrpe -H $HOSTADDRESS$ -t 60 -p 5666 -c check_toprcpu_linux
}
and added to a event_handler in my check_cpu service:

Code: Select all

define service {
	host_name			XXX.XXX.XXX.XXX
	service_description		CPU Stats
	use				xiwizard_nrpe_service
	check_command			check_nrpe!check_cpu_stats!-a '-w 85 -c 90'!!!!!!
	max_check_attempts		1
	check_interval			5
	retry_interval			1
	check_period			xi_timeperiod_24x7
	event_handler			check_topcpu_linux
	event_handler_enabled		1
	notification_interval		60
	notification_period		xi_timeperiod_24x7
	notifications_enabled		1
	contacts			nagiosadmin
	_xiwizard			linux-server
	register			1
	}	
But when I force "Submit passive check result" nothing happens, the script don't execute (there aren't the file in /tmp/)

So, what is what i'm doing wrong?

Thank you so much!
:D

Re: Problem executing Handler Script

Posted: Mon Nov 27, 2017 2:57 pm
by kyang
Before I start asking any questions,
define command {
command_name check_topcpu_linux
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -t 60 -p 5666 -c check_toprcpu_linux
}
Is that command copied or did you type it? Because check_toprcpu_linux is misspelled? I think it should be check_topcpu_linux right?

Re: Problem executing Handler Script

Posted: Tue Nov 28, 2017 6:54 am
by KRVS
kyang wrote:Before I start asking any questions,
define command {
command_name check_topcpu_linux
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -t 60 -p 5666 -c check_toprcpu_linux
}
Is that command copied or did you type it? Because check_toprcpu_linux is misspelled? I think it should be check_topcpu_linux right?
I don't know how to feel right now... that's the problem, obviously... :lol:.. I've gone over it many times!! well... thank you so much, it's my first time with handler scripts, and I think I was making something wrong with nagios, not with my spell hahahaha.

THANKS! :D

Re: Problem executing Handler Script

Posted: Tue Nov 28, 2017 10:37 am
by kyang
No problem! As I was looking I saw it :D

Did you have any more questions or are we good to lock this up?