Skip to content

Commit

Permalink
Script para Adicionar Hosts em manutenção de maneira automatica
Browse files Browse the repository at this point in the history
  • Loading branch information
lsa1es committed Aug 14, 2015
1 parent 9a3cf27 commit ee20f9b
Showing 1 changed file with 122 additions and 0 deletions.
122 changes: 122 additions & 0 deletions Outage/Outage_ITIL.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#!/bin/sh
#
# Script que Insere Hosts em Outage(Manutencao) de maneira automatica.
#
#
# Author: Luiz Sales - [email protected]
# Blog : www.redhate.me
#


# VARIABLES


#HOSTNAME=''
API='' # http://localhost/api_jsonrpc.php

# CONSTANT VARIABLES
ZABBIX_USER=''
ZABBIX_PASS=''

HOSTNAME=$1
DATETIME_INICIO=$(date -d "$2" "+%s")
DATETIME_FINAL=$(date -d "$3" "+%s")
CRQNUMBER=$4
PERIOD=$(expr $DATETIME_FINAL - $DATETIME_INICIO)


help() {
echo "****************************************"
echo "** **"
echo "** OUTAGE API **"
echo "** **"
echo "****************************************"
echo
echo
echo "$0 HOST 'MM/DD/AAA HH:MM:SS' 'MM/DD/AAA HH:MM:SS' 'NOME DA MANUTENCAO'"
echo "$0 HOST '07/12/2015 23:00:00' '7/13/2015 2:00:00' 'NOME DA MANUTENCAO'"
echo
echo
}

authenticate()
{
wget -O- -o /dev/null $API --header 'Content-Type: application/json-rpc' --post-data "{
\"jsonrpc\": \"2.0\",
\"method\": \"user.login\",
\"params\": {
\"user\": \"$ZABBIX_USER\",
\"password\": \"$ZABBIX_PASS\"},
\"id\": 0}" | cut -d'"' -f8
}
AUTH_TOKEN=$(authenticate)

get_host_id() {
wget -O- -o /dev/null $API --header 'Content-Type: application/json-rpc' --post-data "{
\"jsonrpc\": \"2.0\",
\"method\": \"host.get\",
\"params\": {
\"output\": [
\"hostid\"
],
\"filter\": {
\"host\" : [ \"$HOSTNAME\" ]
}
},
\"auth\": \"$AUTH_TOKEN\",
\"id\": 1}" | awk -v RS='{"' -F: '/^hostid/ {print $2}' | awk -F\" '{print $2}'
}
HOSTID=$(get_host_id);

outage_mk() {

wget -O- -o /dev/null $API --header 'Content-Type: application/json-rpc' --post-data "{
\"jsonrpc\": \"2.0\",
\"method\": \"maintenance.create\",
\"params\": {
\"name\": \"$CRQNUMBER\",
\"active_since\": \"$DATETIME_INICIO\",
\"active_till\": \"$DATETIME_FINAL\",
\"hostids\": [
\"$HOSTID\"
],
\"timeperiods\": [
{
\"timeperiod_type\": \"0\",
\"every\": \"1\",
\"dayofweek\": \"64\",
\"start_time\": \"$DATETIME_INICIO\",
\"period\": \"$PERIOD\"
}
]
},
\"auth\": \"$AUTH_TOKEN\",
\"id\": 1 }"
}

outage_get() {

wget -O- -o /dev/null $API --header 'Content-Type: application/json-rpc' --post-data "{
\"jsonrpc\": \"2.0\",
\"method\": \"maintenance.get\",
\"params\": {
\"output\": \"extend\",
\"selectHosts\": \"extend\",
\"selectGroups\": \"extend\",
\"selectTimeperiods\": \"extend\"
},
\"auth\": \"$AUTH_TOKEN\",
\"id\": 1 }"
}

if [ -z $1 ]; then
echo
help;
else
echo
outage_mk;
echo
fi

0 comments on commit ee20f9b

Please sign in to comment.