Debug level is set to -1, Verbosity is set to 2.
The python code has been stripped down to simply just printing to a file. The script is chmodded to 777 and the file should be saved in the libexec folder at /usr/local/nagios/libexec.
If I run the script standalone it works perfectly.
Code: Select all
#!/usr/bin/python
import os
import sys
import datetime
def main():
print sys.argv[1:]
with open('new_file.txt', 'a+') as newfile:
newfile.write(str(sys.argv[1:]))
newfile.write(str(datetime.datetime.now()))
if __name__ == '__main__':
main()
Code: Select all
define host {
check_period 24x7
use generic-switch
check_interval 2
notification_interval 5
notification_period 24x7
retry_interval 1
check_command check-host-alive
hostgroups nagios-routers
contact_groups admins
alias test-router
parents network-monitor
host_name 42947219231x5
address *.*.*.*
event_handler test_python
max_check_attempts 5
_parent_id 42947219020x5
notification_options d,r,u,
}
Code: Select all
define command {
command_name test_python
command_line /usr/bin/python $USER1$/go.py "$HOSTNAME$" "$HOSTADDRESS$" "$HOSTSTATE$" "$HOSTATTEMPT$" "$_HOSTPARENT_ID$" "$HOSTSTATETYPE$"
}
Code: Select all
Feb 01 10:49:12 nagios-server.novalocal nagios[19862]: wproc: Registry request: name=Core Worker 19865;pid=19865
Feb 01 10:49:12 nagios-server.novalocal nagios[19862]: wproc: Registry request: name=Core Worker 19866;pid=19866
Feb 01 10:49:12 nagios-server.novalocal nagios[19862]: wproc: Registry request: name=Core Worker 19867;pid=19867
Feb 01 10:49:12 nagios-server.novalocal nagios[19862]: wproc: Registry request: name=Core Worker 19864;pid=19864
Feb 01 10:49:12 nagios-server.novalocal nagios[19862]: Successfully launched command file worker with pid 19868
Feb 01 10:50:01 nagios-server.novalocal sshd[19890]: Connection closed by 127.0.0.1 [preauth]
Feb 01 10:50:13 nagios-server.novalocal nagios[19862]: HOST ALERT: 42947219231x5;DOWN;SOFT;1;CRITICAL - Host Unreachable (*.*.*.*)
Feb 01 10:50:13 nagios-server.novalocal nagios[19862]: HOST EVENT HANDLER: 42947219231x5;DOWN;SOFT;1;test_python
Feb 01 10:51:01 nagios-server.novalocal sshd[19933]: Connection closed by 127.0.0.1 [preauth]
Feb 01 10:51:16 nagios-server.novalocal nagios[19862]: HOST ALERT: 42947219231x5;DOWN;SOFT;2;CRITICAL - Host Unreachable (*.*.*.*)
Feb 01 10:51:16 nagios-server.novalocal nagios[19862]: HOST EVENT HANDLER: 42947219231x5;DOWN;SOFT;2;test_python
Feb 01 10:51:18 nagios-server.novalocal sudo[19946]: centos : TTY=pts/0 ; PWD=/usr/local/nagios/libexec ; USER=root ; COMMAND=/bin/vim :q
Feb 01 10:51:29 nagios-server.novalocal sshd[19957]: Connection closed by 127.0.0.1 [preauth]
Feb 01 10:51:42 nagios-server.novalocal sudo[19978]: centos : TTY=pts/0 ; PWD=/usr/local/nagios/libexec ; USER=root ; COMMAND=/bin/vim migrate_router.py
Feb 01 10:52:01 nagios-server.novalocal sshd[19988]: Connection closed by 127.0.0.1 [preauth]
Feb 01 10:52:19 nagios-server.novalocal nagios[19862]: HOST ALERT: 42947219231x5;DOWN;SOFT;3;CRITICAL - Host Unreachable (*.*.*.*)
Feb 01 10:52:19 nagios-server.novalocal nagios[19862]: HOST EVENT HANDLER: 42947219231x53;DOWN;SOFT;3;test_python
I cannot figure out why the file doesn't write but there are no errors reported in the log. Does it run the python script from a different shell?
EDIT: I just tried the following:
1. replaced the script with a bash script that calls the python script like (python my_script.py)
2. In the error log it says "stderr line 01: python: can't open file 'my_script.py': [Errno 2] No such file or directory" despite them being in the same directory.
What exactly is happening with event handlers? Should I avoid using them and just use check-commands instead?