Skip to content

Instantly share code, notes, and snippets.

@1977er
Created July 11, 2020 22:49
Show Gist options
  • Save 1977er/ab0723de1a2de9caf95cd1c54df1c81b to your computer and use it in GitHub Desktop.
Save 1977er/ab0723de1a2de9caf95cd1c54df1c81b to your computer and use it in GitHub Desktop.
Zabbix: LowLevelDiscovery json/data wrapper (needed for legacy versions)
#!/bin/bash
# usage:
# $ cat input.txt
# dom01
# dom02
# dom10
# dom23
#
# cat input.txt | ./lld-wrapper.sh "#FOO"
# initialize data
echo '{"data":['
# read all lines from stdin
while read line
do
arr_lines+="$last "
last=$line
done < "${2:-/dev/stdin}"
# build the first lines
for arr_line in $arr_lines; do
echo " {\"{$1}\":\"$arr_line\"},"
done
# build the last line
echo " {\"{$1}\":\"$last\"}"
# terminate data
echo ']}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment