11

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.

SharpEdge
  • 210
  • 2
  • 8
  • 1
    According to the [manual](https://www.zabbix.com/documentation/2.4/manual/web_monitoring), you should be able to use template for web scenarios already in 2.2. – StephenKing Jun 16 '15 at 15:31
  • You are right the problem is not due to the template creating web scenarios. The problem is that it's not possible to use LLD with "web scenarios". – SharpEdge Jun 17 '15 at 09:50
  • Thank you man, is so bad serverfault? – SharpEdge Jun 19 '15 at 11:07
  • As far as i know you can create your own custom low level discovery? – Navern Jun 19 '15 at 12:02
  • Also you have zabbix_api. It's pretty useful. Try look at https://www.zabbix.com/documentation/2.4/manual/api/reference/httptest – Navern Jun 19 '15 at 12:03
  • I know that with the API you could do anything but i would prefer if there is some solution that follows the Zabbix pattern – SharpEdge Jun 19 '15 at 12:07
  • 1
    @peterh interestingly, of your spree of similar comments, most of them seem to be on well-received questions with well received answers. – BE77Y Jun 19 '15 at 15:03

2 Answers2

2

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
chicks
  • 3,639
  • 10
  • 26
  • 36
The_Pingu
  • 31
  • 3
0

Here a script that maybe will help you. This script read a list with URL and create web scenario direct in the zabbix database.

Joao Vitorino
  • 146
  • 1
  • 9