我正在使用一个名为PRTG的监控系统来监视我们的环境。PRTG建议使用一个脚本来监视名为SSH脚本的进程。脚本需要存储在/var/prtg/脚本中。
我找到了一个用于PRTG的脚本:
#!/bin/sh
pgrep wrapper $1 2>&1 1>/dev/null
if [ $? -ne 0 ]; then
echo "1:$?:$1 Down"
else
echo "0:$?:OK"
fi但是,PRTG在Web中返回以下错误代码:
响应格式不正确:"pgrep:只有一种模式可以尝试‘pgrep--帮助’获取更多信息。1:0:包装下“
但是,当我在Linux服务器上运行脚本时,它会打印出:
0:1:好
所以我的问题是什么是最好的脚本来告诉PRTG一个进程是“倒”还是“向上”?
###################编辑以作进一步澄清:
我修改了脚本,它在命令line...but上运行得很好,看起来问题在于它是如何读取输出的。显然它的格式不对。这是我的剧本:
#!/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 "So...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因此,我猜now...the的问题是,如何让这个脚本输出PRTG想要看到的内容?
发布于 2022-03-12 13:29:31
根据您对脚本所做的更改,应该如下所示,并调用如下示例: servicecheck.sh sshd
#!/bin/sh
pgrep -x $1 2>&1 1>/dev/null
if [ $? -ne 0 ]; then
echo "1:$?:$1 Down"
else
echo "0:$?:OK"
fihttps://stackoverflow.com/questions/67216170
复制相似问题