zoukankan      html  css  js  c++  java
  • Zabbix批量添加item

    #!/bin/bash

    ##### https://www.zabbix.com/documentation/3.0/manual/api/reference/user/login
    hostname=10.0.5.15

    gethostid(){
    hostid=`curl -s -X POST -H 'Content-Type:application/json' -d '
    {
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
    "output": ["hostid"],
    "filter": {
    "host": [
    "'$hostname'"
    ]
    }
    },
    "auth": "ca8a7ae867dac1d4a213c3afb6defcca8a7ae867dac1d4a21",
    "id": 1
    }' http://hostip:port/api_jsonrpc.php | jq . | grep hostid | awk -F':' '{print $2}' | sed 's/"//g' | sed 's/ //g'`
    echo $hostid
    }

    getinterfaceid(){
    interfaceid=`curl -s -X POST -H 'Content-Type:application/json' -d ' 
    {
    "jsonrpc": "2.0",
    "method": "hostinterface.get",
    "params": {
    "output": "extend",
    "hostids": "'$hostid'"
    },
    "auth": "ca8a7ae867dac1d4a213c3afb6defcca8a7ae867dac1d4a21",
    "id": 1
    }' http://hostip:port/api_jsonrpc.php | jq . | grep interfaceid | awk -F':' '{print $2}' | sed 's/"//g' | sed 's/ //g' | sed 's/,//g'`
    echo $interfaceid
    }

    getapplicationid(){
    applicationid=`curl -s -X POST -H 'Content-Type:application/json' -d ' 
    {
    "jsonrpc": "2.0",
    "method": "application.get",
    "params": {
    "output": "extend",
    "hostids": "'$hostid'",
    "sortfield": "name"
    },
    "auth": "ca8a7ae867dac1d4a213c3afb6defcca8a7ae867dac1d4a21",
    "id": 1
    }' http://hostip:port/api_jsonrpc.php | jq . | grep -B 2 HAPROXY | grep applicationid | awk -F':' '{print $2}' | sed 's/"//g' | sed 's/ //g' | sed 's/,//g'`
    echo $applicationid
    }

    doexec(){
    for i in `cat ha_server.txt | awk -F',' '{print $1}'` 
    do
    curl -s -X POST -H 'Content-Type:application/json' -d ' 
    {
    "jsonrpc": "2.0",
    "method": "item.create",
    "params": {
    "name": "'$i'",
    "key_": "'$i'",
    "hostid": "'$hostid'",
    "type": 0,
    "value_type": 3,
    "delta": 2,
    "interfaceid": '$interfaceid',
    "applications": [
    "'$applicationid'"
    ],
    "delay": 60
    },
    "auth": "ca8a7ae867dac1d4a213c3afb6defcca8a7ae867dac1d4a21",
    "id": 1
    }' http://hostip:port/api_jsonrpc.php
    done
    }

    gethostid
    getinterfaceid
    getapplicationid
    doexec

     
  • 相关阅读:
    CPU使用率终极计算
    elementui
    spring security oauth2
    maven bom
    vue jsx
    [spring cloud] feign声明
    加分项
    JAVA日报
    JAVA日报
    JAVA日报
  • 原文地址:https://www.cnblogs.com/hyming011/p/8252221.html
Copyright © 2011-2022 走看看