Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # GLOBAL VARIABLES #######################################################################
- URL='http://IP/zabbix/api_jsonrpc.php' # URL/IP Zabbix. #
- HEADER='Content-Type:application/json' #
- USER='"Admin"' # Enter your username. #
- PASS='"zabbix"' # CEnter your password. #
- # END ####################################################################################
- # ARGUMENTS AND VARIABLES ################################################################
- SERVICEID=$2 # ARG $2 = Place SLA serviceid. #
- PARENTID=$3 # ARG $3 = Place SLA PARENTID #
- DAYS=$3 # ARG $3 = Enter the desired number of days for the SLA filter. #
- DIA=`date +%s` #
- TODAY=`date -d '' '+%s'` #
- MONDAY=$([ $(date -d 'last mon' '+%V') -eq $(date '+%V') ] && date -d 'last mon' '+%s' || date -d '' '+%s')
- MONTH=`date -d $(date '+%Y-%m-01') '+%s'` #
- VERSION="1.5.0" #
- UPDATE="15/06/2018" #
- # END ####################################################################################
- # API AUTENTICATION ######################################################################
- autenticate()
- {
- JSON='
- {
- "jsonrpc": "2.0",
- "method": "user.login",
- "params": {
- "user": '$USER',
- "password": '$PASS'
- },
- "id": 0
- }'
- curl -s -X POST -H "$HEADER" -d "$JSON" "$URL" |cut -d '"' -f8
- }
- TOKEN=$(autenticate) # Token obtained by Zabbix
- # END ###################################################################################
- # FUNCTION LLD ##########################################################################
- function lld
- {
- sla ()
- {
- JSON='
- {
- "jsonrpc": "2.0",
- "method": "service.get",
- "params": {
- "output": ["name","goodsla","serviceid","showsla","status"],
- "selectTrigger":[ "triggerid","description","priority" ],
- "selectParent":{ "name":[ "description" ],
- "selectDependencies" : "serviceid",
- "filter":{"name":["$PID"],
- "serviceids":["self.serviceids"]
- }
- }
- }
- ,
- "auth": "'$TOKEN'",
- "id": 1}'
- command01=(`curl -s -X POST -H "$HEADER" -d "$JSON" "$URL" |python3 -mjson.tool | jq '.result | map({name,serviceid,parentserviceid:.parent.serviceid?}) | map(select(.parentserviceid | test("'$SERVICEID'|'$PARENTID'"))) | map({name, serviceid})'| grep "serviceid" |cut -d ":" -f 2 |sed 's/ //g' |sed 's/[",]//g'`)
- command02=(`curl -s -X POST -H "$HEADER" -d "$JSON" "$URL" |python3 -mjson.tool | jq '.result | map({name,serviceid,parentserviceid:.parent.serviceid?}) | map(select(.parentserviceid | test("'$SERVICEID'|'$PARENTID'"))) | map({name, serviceid})'| grep "name" |cut -d ":" -f 2 |sed 's/ //g' |sed 's/[",]//g'`)
- command03=(`curl -s -X POST -H "$HEADER" -d "$JSON" "$URL" |python3 -mjson.tool | jq '.result | map({goodsla,name,serviceid,parentserviceid:.parent.serviceid?})| map(select(.parentserviceid | test("'$SERVICEID'|'$PARENTID'")))| map({name, goodsla})' | grep "goodsla"| cut -d ":" -f2| sed 's/ //g'|sed 's/"//g'`)
- length=${#command01[@]}
- printf "{\n"
- printf '\t'"\"data\":["
- for ((i=0;i<$length;i++))
- do
- printf '\n\t\t{'
- printf "\"{#SLAID}\":\"${command01[$i]}\", \"{#SLANAME}\":\"${command02[$i]}\", \"{#SLAGOOD}\":\"${command03[$i]}\"}"
- if [ $i -lt $[$length-1] ];then
- printf ','
- fi
- done
- printf "\n\t]\n"
- printf "}\n"
- }
- sla
- }
- # END ###################################################################################
- # ARGUMENT OPTION $1 #
- ###################################
- case $1 in #
- LLD) lld; #
- ;; #
- *) #
- # END #############################
- exit ;;
- esac
- # END SCRIPT ###########################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement