Ad Widget

Collapse

Zabbix and Oxidized

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • slpefanis
    Member
    • Jan 2020
    • 52

    #1

    Zabbix and Oxidized

    Hi All

    Not asking for help, just sharing something in the hopes it helps some others.

    We are running zabbix and a distributed enviroment and I wanted a way to sync data from Zabbix back to my oxidised enviroment so that it can automatically add/remove hosts as we adjust in Zabbix. I wasn't able to find anything online so I put together this script as an starting point for getting data from Zabbix via the API and pushing it to a router.db file.

    This is by no means perfect and it's just my starting point.

    Script is below, some notes from my enviroment:
    • Zabbix and Oxidised is on the same server so the router.db is local
    • My zabbix enviroment isn't in the folder /zabbix, so the root URL is https://zabbix.site.com
    • I'm doing this by template ID, but you can use whatever
    • We put the IP in the "host" field which is why this works for us
    Code:
    #!/bin/bash
    
    # Store the output of the curl command
    output=$(curl -sk -X POST "https://zabbixurl/api_jsonrpc.php" \
    -H "Content-Type: application/json-rpc" \
    -d '{
        "jsonrpc": "2.0",
        "method": "host.get",
        "params": {
            "output": ["hostid", "host"],
            "templateids": "template_id",
            "sortfield": "host"
        },
        "auth": "auth_key",
        "id": 1
    }')
    
    # Parse the JSON output and generate the host:ip list, then output to router.db
    echo "$output" | jq -r '.result[] | "\(.host):ios"' > router.db
    
    # Execute the reload command
    curl http://oxidisedurl:8888/reload
    I've made this a cronjob and it should create the router.db file for me. You could look at exentding this and passing the SSH username/password/enable details from macro's from the Zabbix server and/or use the interface IP for some more funcationality.
    Last edited by slpefanis; 01-03-2024, 23:48.
Working...