Ad Widget

Collapse

Zabbix API access from Command Line.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wesmason
    Junior Member
    • Oct 2017
    • 6

    #1

    Zabbix API access from Command Line.

    I've looked around a little and haven't seen much on this front. I have a Zabbix server, and in the process of migration, I have a bulk of copy/paste from old system (would you believe Nagios?) to new system. I don't relish this task so I decided to see what I could manage via API.

    I have some experience pulling out info from the API to get me hostnames for machines I have added to a template. I have expanded this into a bash/curl/jq script to allow me to make all the calls I need to gather information from the API, but via the command line so my other scripts can act on that.

    Example to query the hostname and get the hostid:
    Code:
    $ ./api -m host.get -f '"host": "myhost.com"' -r .hostid
    11
    This is not limited to getting items. Example to query and delete a macro from a host:
    Code:
    $ ./api -m usermacro.get -p '"hostids": "11"'
    {
      "value": "test",
      "macro": "{$TEST}",
      "hostid": "11",
      "hostmacroid": "5"
    }
    $ ./api -m usermacro.delete -a -p '"5"'
    [
      "5"
    ]
    Any interest for me to share it?
    Last edited by wesmason; 28-12-2017, 15:56.
  • kloczek
    Senior Member
    • Jun 2006
    • 1771

    #2
    Originally posted by wesmason
    I've looked around a little and haven't seen much on this front.
    Try to hae look on https://github.com/kloczek/zapish
    http://uk.linkedin.com/pub/tomasz-k%...zko/6/940/430/
    https://kloczek.wordpress.com/
    zapish - Zabbix API SHell binding https://github.com/kloczek/zapish
    My zabbix templates https://github.com/kloczek/zabbix-templates

    Comment

    Working...