Page 1 of 1

why my own script not run on nagios

Posted: Sun Jul 31, 2016 4:03 am
by baber
dear all
Hi

i have created a script for check babak word in a tt file and say if it find that show critical and if not find show ok when i run my script it work correctly

i do these configs for add to nagios monitor :

1 - put my script in this path : /usr/local/nagios/libexec/check_babak.sh
my script this is :

Code: Select all

#!/bin/bash
grep -r 'babak' /tmp/tt > /tmp/p.txt
if [ -s "/tmp/p.txt" ]
then
echo "CRITICAL."
exit 2

else
echo "OK."
exit 0

fi
2 - add this to command.cfg file

Code: Select all

# 'check_babak' command definition
define command{
        command_name    check_babak
        command_line    $USER1$/check_babak -H $HOSTADDRESS$
        }

3 - add this line to nrpe.cfg file :

Code: Select all

command[check_babak]=/usr/local/nagios/libexec/check_babak.sh
and add this to my localhost.cfg file

Code: Select all

define service{
        use                             local-service         ; Name of service template to use
        host_name                       localhost
        service_description             babak
	check_command			check_babak
        }

and this is content of my /tmp

ll /tmp

Code: Select all

-rwxr-xr-x. 1 root   root        199 Jul 23 12:41 11.sh
-rwxr-xr-x. 1 root   root         85 Jul 23 14:08 12.sh
-rw-r--r--. 1 root   root        256 Jul 23 12:40 1.txt
-rw-r--r--. 1 root   root          0 Jul 31 11:57 2.txt
-rwxr-xr-x. 1 nagios nagios      233 Jul 19 11:20 auto.sh
-rwxr-xr-x. 1 root   root      35406 Jul 23 13:35 check_esxi_hardware.py
-rw-r--r--. 1 root   root       1932 Jul 23 19:59 check_esx_time.sh
-rw-r--r--. 1 root   root       5008 Jul 24 11:54 client2.cfg
-rw-r--r--. 1 root   root       5552 Jul 24 11:54 client3.cfg
-rw-r--r--. 1 root   root       6090 Jul 24 11:54 client4.cfg
-rw-r--r--. 1 root   root       4345 Jul 25 09:58 client.cfg
-rw-r--r--. 1 root   root       1292 Jul 27 14:45 client.sh
-rwxr-xr-x. 1 root   root   15047120 Jul 29  2014 hpssacli
drwx------. 2 babak  babak      4096 Jun 26 15:56 keyring-PZM9w3
drwxr-xr-x. 2 root   root       4096 Jul 28 09:57 libexec
-rwxr-xr-x. 1 root   root       6225 Jul 23 10:46 nag3.sh
drwxr-xr-x. 2 root   root       4096 Jul 28 09:57 nagios
-rwxr-xr-x. 1 root   root       6225 Jul 23 10:14 nagios1.sh
-rwxr-xr-x. 1 root   root       3710 Jul 23 00:52 nagios2.sh
drwxrwxr-x. 3 root   root       4096 Jan 31 15:14 nagios-4.1.1
-rwxr-xr-x. 1 root   root      11050 Jul 27 08:52 nagios.sh
-rwxr-xr-x. 1 root   root        656 Jul 20 12:55 nag.sh
-rwxr-xr-x. 1 root   root        130 Jul 31 12:40 new.sh
drwx------. 2 babak  babak      4096 Jun 26 16:00 orbit-babak
drwx------. 2 gdm    gdm        4096 Jun 26 15:56 orbit-gdm
-rw-r--r--. 1 root   root          0 Jul 31 13:17 p.txt
drwx------. 2 babak  babak      4096 Jun 26 15:56 pulse-ex3o8rRkmIrN
drwx------. 2 root   root       4096 Jan 23  2016 pulse-PoV2Od8uMDWs
-rw-r--r--. 1 root   root       1338 Jul 25 12:15 python.txt
-rw-r--r--. 1 root   root       4041 Jul 27 16:12 ServerName.cfg
-rwxr-xr-x. 1 root   root        233 Jul 21 13:42 test.sh
-rwxr-xr-x. 1 root   root         84 Jul 31 11:42 tt
drwx------. 2 root   root       4096 Jul 17 08:25 vmware-root
-rw-r--r--. 1 root   root       2085 Jul 31 08:33 windows.cfg
-rw-r--r--. 1 root   root       2066 Jul 25 17:09 windowsIIS.cfg

Code: Select all

ll /usr/local/nagios/libexec/
total 23896
-rwxr-xr-x. 1 root   root     796116 Aug  3  2015 box293_check_vmware.pl
-rwxr-xr-x. 1 nagios nagios   446023 Feb 24 15:47 check_apt
-rwxr-xr-x. 1 nagios nagios      130 Jul 31 12:41 check_babak.sh
-rwxr-xr-x. 1 nagios nagios     2309 Feb 24 15:47 check_breeze
-rwxr-xr-x. 1 nagios nagios   183540 Feb 24 15:47 check_by_ssh
lrwxrwxrwx. 1 root   root          9 Feb 24 15:47 check_clamd -> check_tcp
-rwxr-xr-x. 1 nagios nagios   138854 Feb 24 15:47 check_cluster
-r-sr-xr-x. 1 root   nagios   177423 Feb 24 15:47 check_dhcp
-rwxr-xr-x. 1 nagios nagios   178510 Feb 24 15:47 check_dig
-rwxr-xr-x. 1 nagios nagios   461246 Feb 24 15:47 check_disk
-rwxr-xr-x. 1 nagios nagios     9348 Feb 24 15:47 check_disk_smb
-rwxr-xr-x. 1 nagios nagios   195011 Feb 24 15:47 check_dns
-rwxr-xr-x. 1 nagios nagios    87562 Feb 24 15:47 check_dummy
-rwxr-xr-x. 1 root   root     132285 Apr 12 09:55 check_esx3-0.5.pl
-rwxr-xr-x. 1 root   root      35406 Jul 23 13:35 check_esxi_hardware.py
-rwxr-xr-x. 1 root   root       1932 Jul 23 19:59 check_esx_time.sh
-rwxr-xr-x. 1 nagios nagios     3542 Feb 24 15:47 check_file_age
-rwxr-xr-x. 1 nagios nagios     6375 Feb 24 15:47 check_flexlm
lrwxrwxrwx. 1 root   root          9 Feb 24 15:47 check_ftp -> check_tcp
-rwxr-xr-x. 1 nagios nagios    24458 Feb  1 12:20 check_hp
-rwxr-xr-x. 1 nagios nagios   177058 Feb 24 15:47 check_hpjd
-rwxr-xr-x. 1 nagios nagios   607973 Feb 24 15:47 check_http
-r-sr-xr-x. 1 root   nagios   183628 Feb 24 15:47 check_icmp
-rwxr-xr-x. 1 nagios nagios   147472 Feb 24 15:47 check_ide_smart
-rwxr-xr-x. 1 nagios nagios    15238 Feb 24 15:47 check_ifoperstatus
-rwxr-xr-x. 1 nagios nagios    13386 Feb 24 15:47 check_ifstatus
lrwxrwxrwx. 1 root   root          9 Feb 24 15:47 check_imap -> check_tcp
-rwxr-xr-x. 1 nagios nagios     6947 Feb 24 15:47 check_ircd
lrwxrwxrwx. 1 root   root          9 Feb 24 15:47 check_jabber -> check_tcp
-rwxr-xr-x. 1 nagios nagios   160017 Feb 24 15:47 check_load
-rwxr-xr-x. 1 nagios nagios     6595 Feb 24 15:47 check_log
-rwxr-xr-x. 1 nagios nagios    22730 Feb 24 15:47 check_mailq
-rwxr-xr-x. 1 root   root      12103 May 12  2015 check_mem.pl
-rwxr-xr-x. 1 nagios nagios   145542 Feb 24 15:47 check_mrtg
-rwxr-xr-x. 1 nagios nagios   146779 Feb 24 15:47 check_mrtgtraf
-rwxr-xr-x. 1 nagios nagios   159279 Feb 24 15:47 check_nagios
lrwxrwxrwx. 1 root   root          9 Feb 24 15:47 check_nntp -> check_tcp
lrwxrwxrwx. 1 root   root          9 Feb 24 15:47 check_nntps -> check_tcp
-rwxrwxr-x. 1 nagios nagios    75493 Apr 14 10:11 check_nrpe
-rwxr-xr-x. 1 nagios nagios   181487 Feb 24 15:47 check_nt
-rwxr-xr-x. 1 nagios nagios   185194 Feb 24 15:47 check_ntp
-rwxr-xr-x. 1 nagios nagios   176999 Feb 24 15:47 check_ntp_peer
-rwxr-xr-x. 1 nagios nagios   172532 Feb 24 15:47 check_ntp_time
-rwxr-xr-x. 1 nagios nagios   213476 Feb 24 15:47 check_nwstat
-rwxr-xr-x. 1 nagios nagios     8926 Feb 24 15:47 check_oracle
-rwxr-xr-x. 1 nagios nagios   161858 Feb 24 15:47 check_overcr
-rwxr-xr-x. 1 nagios nagios   185323 Feb 24 15:47 check_ping
lrwxrwxrwx. 1 root   root          9 Feb 24 15:47 check_pop -> check_tcp
-rwxr-xr-x. 1 nagios nagios   454408 Feb 24 15:47 check_procs
-rwxr-xr-x. 1 nagios nagios   158644 Feb 24 15:47 check_real
-rwxr-xr-x. 1 nagios nagios     9642 Feb 24 15:47 check_rpc
-rwxr-xr-x. 1 nagios nagios     1465 Feb 24 15:47 check_sensors
lrwxrwxrwx. 1 root   root          9 Feb 24 15:47 check_simap -> check_tcp
-rwxr-xr-x. 1 nagios nagios   512977 Feb 24 15:47 check_smtp
-rwxr-xr-x. 1 nagios nagios   523842 Feb 24 15:47 check_snmp
lrwxrwxrwx. 1 root   root          9 Feb 24 15:47 check_spop -> check_tcp
-rwxr-xr-x. 1 nagios nagios   157124 Feb 24 15:47 check_ssh
lrwxrwxrwx. 1 root   root          9 Feb 24 15:47 check_ssmtp -> check_tcp
-rwxr-xr-x. 1 nagios nagios   144374 Feb 24 15:47 check_swap
-rwxr-xr-x. 1 nagios nagios   227727 Feb 24 15:47 check_tcp
-rwxr-xr-x. 1 nagios nagios   159658 Feb 24 15:47 check_time
lrwxrwxrwx. 1 root   root          9 Feb 24 15:47 check_udp -> check_tcp
-rwxr-xr-x. 1 nagios nagios   170002 Feb 24 15:47 check_ups
-rwxr-xr-x. 1 nagios nagios   139632 Feb 24 15:47 check_uptime
-rwxr-xr-x. 1 nagios nagios   137438 Feb 24 15:47 check_users
-rwxr-xr-x. 1 root   root       2711 Jul 24 13:40 check_VM_snapshots
-rwxr-xr-x. 1 nagios nagios     2995 Feb 24 15:47 check_wave
drwxr-xr-x. 4 nagios nagios     4096 Jan 31 15:20 eventhandlers
-rw-r--r--. 1 root   root   15047120 Jul 29  2014 hpssacli
-rwxr-xr-x. 1 nagios nagios   132577 Feb 24 15:47 negate
-rwxr-xr-x. 1 nagios nagios   127379 Feb 24 15:47 urlize
-rwxr-xr-x. 1 nagios nagios     1949 Feb 24 15:47 utils.pm
-rwxr-xr-x. 1 nagios nagios     2791 Feb 24 15:47 utils.sh

i want chk this on my localhost on nagios server

and i have attached my error on nagios

what do i have to do ?

Re: why my own script not run on nagios

Posted: Sun Jul 31, 2016 8:50 pm
by Box293
That is not required, it has nothing to do with NRPE.
baber wrote:3 - add this line to nrpe.cfg file :

Code: Select all

command[check_babak]=/usr/local/nagios/libexec/check_babak.sh
Here is your command definition:
baber wrote:2 - add this to command.cfg file

Code: Select all

    # 'check_babak' command definition
    define command{
            command_name    check_babak
            command_line    $USER1$/check_babak -H $HOSTADDRESS$
            }
Your command is referencing a file called check_babak HOWEVER your file ends in .sh hence it cannot find the file. Try:

Code: Select all

    # 'check_babak' command definition
    define command{
            command_name    check_babak
            command_line    $USER1$/check_babak.sh -H $HOSTADDRESS$
            }