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).

Executing a script from Nagios event handler fails to run的更多相关文章

  1. [翻译]Event Handler Description 事件处理描述

    Event Handler Description 事件处理描述 (自定义控件)   How should a new event handler be defined if it does not ...

  2. Event Handler

    在Event Handler中,有一种特殊的Event Handler,称之为Synchronizer或者Denormalizer,其作用就是为了同步“Query Database”.Query Da ...

  3. SharePoint中Event Handler的触发

    一直以来对于Event Handler的感觉就是:添加.编辑和删除动作之前和动作之后,我们在SharePoint系统中可以做的一些事情 不过在最近处理的一个问题中,发现它在触发时机上出了一点问题   ...

  4. SSIS ->> Event Handler

    Event Handler支持在某个事件触发的时候定义好处理该事件的逻辑,比如错误事件触发是该怎么处理.它跟Control Flow界面相似,就好像执行了另外一个包一样.Event Handler不仅 ...

  5. JPA project Change Event Handler问题解决[转]

    转至:http://my.oschina.net/cimu/blog/278724 这是Eclipse中的一个GUG: Bug 386171 - JPA Java Change Event Handl ...

  6. jquery , find the event handler,找到jquery中的event handler

    找到 dispatch: function (e) { e = b.event.fix(e); var n, r, i, s, o, u = [], a = d.call(arguments), f ...

  7. 为什么Form.Timer的event handler在Form被Dispose之后还是被调到了?

    博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:为什么Form.Timer的event handler在Form被Dispose之后还是被调到了?.

  8. Qt的事件模型(5种使用办法,通常重新实现event handler即可。只有定义控件才需要管理信号的发射)

    Qt的事件模型 1.事件的概念 应用程序对象将系统消息接收为 Qt 事件.应用程序可以按照不同的粒度对事件加以监控.过滤并做出响应. 在 Qt 中,事件是指从 QEvent继承 的对象.Qt将事件发送 ...

  9. linux input如何固定设备event handler

    于qt开发时间.遇到的问题,usb输入设备(鼠标器,usb 电容屏)在动力分配后自己主动input节点,实例usb鼠标停留电后,分配给自己的主动性/dev/input/event0 mouse0.第一 ...

随机推荐

  1. EF查询生成的SQL

    在EF 4和EF 3.5 SP1中,我们可以使用ToTraceString()方法得到EF查询所生成的SQL. using (var context = new TestDBEntities()) { ...

  2. 委托[delegate]_C#

    委托(delegate): 委托声明定义了一种类型,它用一组特定的参数以及返回类型来封装方法.对于静态方法,委托对象封装要调用的方法.对于实例方法,委托对象同时封装一个实例和该实例上的一个方法.如果您 ...

  3. 你需要知道的三个CSS技巧

    各种浏览器之间的竞争的白热化意味着越来越多的人现在开始使用那些支持最新.最先进的W3C Web标准的设备,以一种更具交互性的方式来访问互联网.这意味着我们终于能够利用更强大更灵活的CSS来创造更简洁, ...

  4. Js 变量的作用域

    变量的作用域 所有的变量作用域是指在哪里可用哪里不可用 局部作用域和全局作用域 在js中以函数来分割作用域 在函数里面就叫做局部作用域,在函数外面的就叫全局作用域 在函数里面如果省略var 关键字 那 ...

  5. Poj 3062 Celebrity jeopardy

    1.Link: http://poj.org/problem?id=3062 2.Content: Celebrity jeopardy Time Limit: 1000MS   Memory Lim ...

  6. ALI OSS RequestTimeTooSkewed

    php版阿里oss sdk,请求时抛RequestTimeTooSkewed错误,说时间差距太大,搜了一下发现是服务器的时间设置问题. 我们在安装完Centos Linux操作系统之后,点击系统的时间 ...

  7. Linux ed

    ed 编辑器是 Linux 操作系统下最简单的文本编辑器.它是以行为单位对文件进行编辑的编辑器,而不像 MS-DOS 系统下的 edit 那样是以整个屏幕框架为单位对文件进行编辑的.因此,如果你已经习 ...

  8. dom4j api 详解--XPath 节点详解

    dom4j api 详解 http://871421448.iteye.com/blog/1546955 XPath 节点 http://www.w3school.com.cn/xpath/xpath ...

  9. 解决ListView滑动时卡的问题,实现异步加载图片解决

    ListView是最为常见的空间之一,现在的应用的呈现形式大多数都需要用到ListView来呈现,以列表的方式最直观最便于操作. 那么在使用的过程中大家一定使用adapter适配器来匹配这个ListV ...

  10. 修改wamp的apache默认端口80以及www目录

    修改wamp的apache默认端口80以及www目录 以修改为8088端口和D:/workphp目录为例. 修改为8088端口 左键托盘图标,在“Apache”里可以直接打开httpd.conf,查找 ...