Skip to content

Instantly share code, notes, and snippets.

@sesukovs
Created February 19, 2017 16:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save sesukovs/4fad54c051c92b14c26e2ca2c42e166c to your computer and use it in GitHub Desktop.
Save sesukovs/4fad54c051c92b14c26e2ca2c42e166c to your computer and use it in GitHub Desktop.
Bash script that creates JSON document for Zabbix discovery
#!/bin/bash
VHOST_CONFIG_PATH='/etc/nginx/sites-enabled/'
echo "{"
echo ' "data":['
FIRST=1
while read line; do
if [ $FIRST != 0 ]; then
FIRST=0
else
ELEMENT="{ \"{#DOMAIN}\":\"$DOMAIN\" },"
echo " $ELEMENT"
fi
DOMAIN=$line
done <<< "$(find $VHOST_CONFIG_PATH -type f | awk -F '/' '{print $5}')"
ELEMENT="{ \"{#DOMAIN}\":\"$DOMAIN\" }"
echo " $ELEMENT"
echo ' ]'
echo "}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment