Skip to content

Commit

Permalink
Adding zbx macro support in zabbix_cli wrapper
Browse files Browse the repository at this point in the history
Signed-off-by: Fabian Arrotin <arrfab@centos.org>
  • Loading branch information
arrfab committed Nov 29, 2021
1 parent 8fc9feb commit 48dce7c
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion templates/scripts/zabbix_host_tool.j2
Expand Up @@ -14,6 +14,8 @@ You need to call the script like this : $0 -arguments
-n : node/host to configure in zabbix (mandatory)
-t : template to link to host in zabbix
-g : zabbix groups the node should be member of
-m : zabbix hostmacro to update
-v : field value (can be used for macro)
-h : display this help
EOF
Expand All @@ -26,7 +28,7 @@ if [ -z "$1" ] ; then
fi
}

while getopts "hn:t:g:" option
while getopts "hn:t:g:m:v:" option
do
case ${option} in
h)
Expand All @@ -42,6 +44,12 @@ do
g)
zabbix_group=${OPTARG}
;;
m)
zabbix_macro=${OPTARG}
;;
v)
zabbix_field_value=${OPTARG}
;;
?)
usage
exit
Expand Down Expand Up @@ -87,3 +95,17 @@ if [ ! -z "${zabbix_group}" ]; then
fi
fi

#
if [ ! -z "${zabbix_macro}" ]; then
if [ ! -z "${zabbix_field_value}" ] && [ ! -z "${zabbix_field_value}" ] ; then
zabbix-cli -o json -C "define_host_usermacro ${zabbix_host} \"${zabbix_macro}\" \"${zabbix_field_value}\" " >/dev/null
if [ "$?" -ne "0" ] ; then
exit 1
else
exit 2
fi
else
exit 0
fi
fi

0 comments on commit 48dce7c

Please sign in to comment.