zoukankan      html  css  js  c++  java
  • Executing a script from Nagios event handler fails to run

    I have Nagios running on a webserver. For this one Nagios service check in particular, if it fails, it will run a script. This script is triggered via Nagios event handlers.

    Nagios event handler command:

    define command{
            command_name    testDisableServer
            command_line    /usr/local/nagios/etc/objects/event_handlers/testDisableServer.sh
    }

    I am executing a script called testDisableServer.sh from Nagios event handlers that looks like this:

    #!/bin/bash
    wall "Script execution started";/usr/bin/sudo /root/scripts/disableServer.sh force

    This script 'testDisableServer.sh' has the following permissions:

    -rwxr-xr-x 1 nagios nagios 2.0KOct1214:57 testDisableServer.sh

    When the service goes down, I will get a wall post in my SSH connection saying "Script execution started", but it will not trigger my disableServer.sh script. I tried to place another wall post inside of disableServer.sh and it did not trigger it.

    This script is being run by the user 'nagios'. 'nagios' was added in visudo, as such:

    nagios  ALL=(ALL)NOPASSWD:/root/scripts/disableServer.sh

    Running this script as the user 'nagios' from a command line works perfectly fine. However, when the event handler triggers it, there is no output. I tried to catch the output into a log file, and I came up with nothing. These are the permissions on /root/scripts/disableServer.sh:

    -rwxr-xr-x   1 root root 2.0KOct1215:01 disableServer.sh

    Why would the event handler hit 'testDisableServer.sh', but not execute 'disableServer.sh' from a Nagios event handler, but work just fine in an SSH connection as the user nagios? BTW, 'testDisableServer.sh' is just an extra layer added to see if the event handlers were working, which they seem to be. This will be removed after this script execution is all sorted out.

    Answer:

    Possibly it's an environment issue (the script is relying on something in its environment that is not available when run by nagios).

    I would change your script (temporarily for debugging only) to:

    #!/bin/bash
    exec 2>/tmp/log."$$"set-x
    wall "Script execution started";/usr/bin/sudo /root/scripts/disableServer.sh force

    And add another set -x at the top of disableServer.sh

    To see what's going on (in the /tmp/log.* files).

  • 相关阅读:
    Cocos2Dx(3)——动作类备忘
    npm publish发布包时出现403错误no_perms Private mode enable, only admin can publish this module:
    使用node.js定义一个web服务器
    node.js中events模块应用
    session应用:验证用户是否已登录
    简单实现三级导航栏
    promise对象代替回调函解决异步操作
    js一行代码解实现数组去重和排序
    中英文切换导航栏(最简单)
    错误:localhost将您重定向的次数过多
  • 原文地址:https://www.cnblogs.com/reynold-lei/p/3149205.html
Copyright © 2011-2022 走看看