我是Zabbix和企业监控的新手。 我刚刚安装了Zabbix 2.4。
我试图监视所有我们的vhosts在不同的服务器上错位的状态。
到目前为止,我想出的唯一解决scheme是为每个要监视的vhost主机手动添加一个Web scenario到Zabbix服务器主机。 但它并不那么方便。
四处搜寻我find了一个具有部分function的论坛主题:使用从目标服务器读取所有vhosts (通过macro )的template ,并为每个vhost创build一个Web scenario 。
编辑 :此解决scheme(基于Zabbix 2.2)不起作用,因为不可能使用LLD(低级别发现)与Web scenarios 。
自从11月14日以来,有一个function请求在Web scenarios实现LLD 。
问题是如果在等待function实现的时候如何解决这个问题,或者我的方法是完全错误的,那么是否有一些解决scheme或者build议。
这里可能会帮助你的脚本。 该脚本通过URL读取一个列表,并直接在zabbix数据库中创buildweb场景。
我使用了一个使用zabbix API来创build场景的脚本。
#!/bin/bash read -s -p "Enter AdminAPI password: " password response=$(curl "http://192.168.0.5:10052/api_jsonrpc.php" -H "Content-Type: application/json-rpc" --data @<(cat <<EOF { "jsonrpc": "2.0", "method": "user.login", "params": { "user": "AdminAPI", "password": "$password" }, "id": 1, "auth": null } EOF )) read token id <<<$(echo $response | jq -r '.result, .id') while read -p "enter quit or an url for a new web scenario" url && [ $url != "quit" ] do shorturl=$(echo $url | sed 's:.*//::') echo --------- echo $token echo $url echo $shorturl echo --------- # the hostid is visible when you are on the host page on the zabbix interface #le hostid est visible dans l'url de de la page du host sur zabbix ici bunsrv curl "http://192.168.0.5:10052/api_jsonrpc.php" -H "Content-Type: application/json-rpc" --data @<(cat <<EOF { "jsonrpc": "2.0", "method": "httptest.create", "params": { "name": "$shorturl", "hostid": "10120", "steps": [ { "name": "Homepage", "url": "$url", "status_codes": 200, "no": 1 } ] }, "auth": "$token", "id": $id } EOF ) done
和触发器:
curl "http://192.168.0.5:10052/api_jsonrpc.php" -H "Content-Type: application/json-rpc" --data @<(cat <<EOF { "jsonrpc": "2.0", "method": "trigger.create", "params": [ { "description": "Web scenario $shorturl failed: {ITEM.VALUE} from {HOST.NAME}", "expression": "{BUNSRV:web.test.fail[$shorturl].last()}<>0 and {BUNSRV:web.test.error[$shorturl].strlen()}>0", "priority": "2" } ], "auth": "$token", "id": $id } EOF ) done