问题描述
我正在使用一个名为 PRTG 的监控系统来监控我们的环境。 PRTG KB 建议使用称为 SSH 脚本的脚本来监视进程。脚本需要存储在 /var/prtg/scripts 中。
我发现了一个有人用于 PRTG 的脚本:
#!/bin/sh
pgrep wrapper $1 2>&1 1>/dev/null
if [ $? -ne 0 ]; then
echo "1:$?:$1 Down"
else
echo "0:$?:OK"
fi
响应格式不正确:“pgrep:只能提供一种模式尝试`pgrep --help'了解更多信息。1:0:Wrapper Down”
但是,当我在 Linux 服务器上运行脚本时,它会打印出来:
0:1:好的
所以我的问题是,用来告诉 PRTG 进程是“关闭”还是“启动”的最佳脚本是什么?
################### 编辑以进一步澄清:
我更改了脚本,它在命令行上工作得很棒……但问题似乎在于 PRTG 读取输出的方式。显然它的格式不正确。所以这是我的脚本:
#!/bin/bash
SERVICE="wrapper"
if pgrep -x "$SERVICE" >/dev/null
then
echo "$SERVICE is running"
else
echo "$SERVICE stopped"
fi
这就是 PRTG 出错的地方:
Response not well-formed: "wrapper is running "
所以...PRTG 是说我使用的传感器希望脚本输出为这种格式:
The returned data for standard SSH Script sensors must be in the following
format:
returncode:value:message
Value has to be a 64-bit integer or float. It is used as the resulting value
for this sensor (for example,bytes,milliseconds) and stored in the
database. The message can be any string (maximum length: 2000 characters).
The SSH script returncode has to be one of the following values:
VALUE DESCRIPTION
0 OK
1 WARNING
2 System Error
3 Protocol Error
4 Content Error
所以我想现在...问题是如何让该脚本输出 PRTG 想要看到的内容?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)