Advertising:

Ejemplos de llamadas a la API de Zabbix

From Zabbix-ES
Jump to navigation Jump to search
# curl -s -X POST -H 'Content-type:application/json' -d '{"jsonrpc":"2.0","method":"user.login","params":{ "user":"Admin","password":"zabbix"},"auth":null,"id":0}' http://192.168.1.10/zabbix/api_jsonrpc.php | jq
{
  "jsonrpc": "2.0",
  "result": "2ed00d4a49884280509a622fc7549381",
  "id": 0
}
# curl -s -X POST -H 'Content-type:application/json' -d '{"jsonrpc":"2.0","method": "trigger.get","params": {"triggerids": "39311","output": "extend","selectFunctions": "extend"},"auth": "2ed00d4a49884280509a622fc7549381","id":0}' http://192.168.1.10/zabbix/api_jsonrpc.php | jq
{
  "jsonrpc": "2.0",
  "result": [
    {
      "triggerid": "39311",
      "expression": "{56826}>{$FS_USED_CRITICAL:\"/var\"}",
      "description": "Alto consumo de Filesystem /var {ITEM.LASTVALUE}",
      "url": "",
      "status": "0",
      "value": "1",
      "priority": "4",
      "lastchange": "1516105237",
      "comments": "",
      "error": "",
      "templateid": "0",
      "type": "0",
      "state": "0",
      "flags": "4",
      "recovery_mode": "1",
      "recovery_expression": "{56826}<={$FS_USED_CRITICAL:\"/var\"}",
      "correlation_mode": "0",
      "correlation_tag": "",
      "manual_close": "1",
      "functions": [
        {
          "functionid": "56826",
          "itemid": "136237",
          "triggerid": "39311",
          "function": "last",
          "parameter": ""
        }
      ]
    }
  ],
  "id": 0
}


# curl -s -X POST -H 'Content-type:application/json' -d '{"jsonrpc": "2.0","method": "event.get","params": {"output": "extend","select_acknowledges": "extend","objectids": "39311","sortfield": ["clock", "eventid"],"sortorder": "DESC"},"auth": "2ed00d4a49884280509a622fc7549381","id": 0}' http://192.168.1.10/zabbix/api_jsonrpc.php | jq
{
  "jsonrpc": "2.0",
  "result": [
    {
      "eventid": "88795",
      "source": "0",
      "object": "0",
      "objectid": "39311",
      "clock": "1516105237",
      "value": "1",
      "acknowledged": "0",
      "ns": "738347765",
      "r_eventid": "0",
      "c_eventid": "0",
      "correlationid": "0",
      "userid": "0",
      "acknowledges": []
    }
  ],
  "id": 0
}


# curl -s -X POST -H 'Content-type:application/json' -d '{"jsonrpc": "2.0","method": "host.get","params": {"filter": {"host": ["test01"]}},"auth": "91d70d9cf402511dfc842a4a152193d0","id": 0}' http://192.168.1.10/zabbix/api_jsonrpc.php | jq
{
  "jsonrpc": "2.0",
  "result": [
    {
      "hostid": "10268",
      "proxy_hostid": "0",
      "host": "test01",
      "status": "0",
      "disable_until": "0",
      "error": "",
      "available": "1",
      "errors_from": "0",
      "lastaccess": "0",
      "ipmi_authtype": "-1",
      "ipmi_privilege": "2",
      "ipmi_username": "",
      "ipmi_password": "",
      "ipmi_disable_until": "0",
      "ipmi_available": "0",
      "snmp_disable_until": "0",
      "snmp_available": "1",
      "maintenanceid": "0",
      "maintenance_status": "0",
      "maintenance_type": "0",
      "maintenance_from": "0",
      "ipmi_errors_from": "0",
      "snmp_errors_from": "0",
      "ipmi_error": "",
      "snmp_error": "",
      "jmx_disable_until": "0",
      "jmx_available": "0",
      "jmx_errors_from": "0",
      "jmx_error": "",
      "name": "test01",
      "flags": "0",
      "templateid": "0",
      "description": "",
      "tls_connect": "1",
      "tls_accept": "1",
      "tls_issuer": "",
      "tls_subject": "",
      "tls_psk_identity": "",
      "tls_psk": ""
    }
  ],
  "id": 0
}


# curl -s -X POST -H 'Content-type:application/json' -d '{"jsonrpc": "2.0","method": "host.get","params": {"filter": {"host": ["5001870c-ce7a-ea65-53b3-b3c227760395"]}},"auth": "91d70d9cf402511dfc842a4a152193d0","id": 0}' http://192.168.1.10/zabbix/api_jsonrpc.php | jq
{
  "jsonrpc": "2.0",
  "result": [
    {
      "hostid": "12383",
      "proxy_hostid": "0",
      "host": "5001870c-ce7a-ea65-53b3-b3c227760395",
      "status": "0",
      "disable_until": "0",
      "error": "",
      "available": "0",
      "errors_from": "0",
      "lastaccess": "0",
      "ipmi_authtype": "-1",
      "ipmi_privilege": "2",
      "ipmi_username": "",
      "ipmi_password": "",
      "ipmi_disable_until": "0",
      "ipmi_available": "0",
      "snmp_disable_until": "0",
      "snmp_available": "0",
      "maintenanceid": "0",
      "maintenance_status": "0",
      "maintenance_type": "0",
      "maintenance_from": "0",
      "ipmi_errors_from": "0",
      "snmp_errors_from": "0",
      "ipmi_error": "",
      "snmp_error": "",
      "jmx_disable_until": "0",
      "jmx_available": "0",
      "jmx_errors_from": "0",
      "jmx_error": "",
      "name": "test02",
      "flags": "4",
      "templateid": "0",
      "description": "",
      "tls_connect": "1",
      "tls_accept": "1",
      "tls_issuer": "",
      "tls_subject": "",
      "tls_psk_identity": "",
      "tls_psk": ""
    }
  ],
  "id": 0
}
# curl -s -X POST -H 'Content-type:application/json' -d '{"jsonrpc":"2.0","method": "","params": {},"auth": "","id":}' http://192.168.1.10/zabbix/api_jsonrpc.php | jq