We needed the ability to sync SNMP data fields into host profile (and extended profile).
The problem was solved using a template and the following external script.
Actually it is quite simple but I can imagine some others will face similar tasks.
Attached there's a readme file with further information.
The problem was solved using a template and the following external script.
Actually it is quite simple but I can imagine some others will face similar tasks.
Attached there's a readme file with further information.
Code:
#!/bin/bash
LOG=/tmp/snmp2hostprofile.log
dbuser=zabbix
dbpass=password
dbname=zabbix
dbhost=localhost
OIFS=$IFS
IFS=","
declare -a args=($*)
IFS=$OIFS
if [ ${#args[*]} -eq 5 ]; then
snmpcmd="snmpget ${args[1]} ${args[0]} ${args[2]}"
snmpoutput=` eval ${snmpcmd} `
tmp1="${snmpoutput#* = }"
value=${tmp1#*: }
profiletype="hosts_"${args[3]}
profilefield=${args[4]}
hostip=${args[0]}
mysql --user=${dbuser} --password=${dbpass} --database=${dbname} -h ${dbhost} -e "INSERT INTO hosts_profiles (hostid, ${profilefield}) VALUES ((SELECT hostid FROM hosts WHERE ip = '${hostip}'), '${value}') ON DUPLICATE KEY UPDATE ${profilefield}='${value}';"
fi
echo ${value}
Comment