How to automate zabbix web scenarios for vhosts?
I'm new to Zabbix and enterprise monitoring. I've just finished installing Zabbix 2.4.
I'm trying to monitor the state of all our vhosts
dislocated on different servers.
Until now the only solution I came up with is to manually add a Web scenario
to the Zabbix Server host for each vhost
I want to monitor. But it's not so handy.
Searching around I have found a forum thread with a partial functioning idea: Using a template
that reads from the target server all the vhosts
(through a macro
) and creates a Web scenario
for each vhost
.
EDIT: This solution (based on Zabbix 2.2) doesn't work because is not possible to use LLD (Low Level Discovery) with Web scenarios
.
There is a Feature Request open since Nov 14 to implement LLD
on Web scenarios
.
QUESTION
The question is if there is some solution or suggestion on how to approach this kind of monitoring while waiting the feature implementation, or maybe my approach is totally wrong.
Solution 1:
I used a script which uses the Zabbix API to create the scenarios.
#!/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
and for the triggers :
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