Send a fake discovery to create some interfaces

zabbix_sender -z 127.0.0.1 -s "Zabbix server" -k net.if.discovery.manual -o '{"data":[{"{#SNMPINDEX}":"1","{#SNMPVALUE}":"1","{#IFADMINSTATUS}":"1","{#IFALIAS}":"","{#IFNAME}":"ether1-gateway","{#IFDESCR}":"ether1-gateway","{#IFTYPE}":"6"},{"{#SNMPINDEX}":"2","{#SNMPVALUE}":"1","{#IFADMINSTATUS}":"1","{#IFALIAS}":"","{#IFNAME}":"ether2-master-local","{#IFDESCR}":"ether2-master-local","{#IFTYPE}":"6"},{"{#SNMPINDEX}":"3","{#SNMPVALUE}":"2","{#IFADMINSTATUS}":"1","{#IFALIAS}":"","{#IFNAME}":"ether3-slave-local","{#IFDESCR}":"ether3-slave-local","{#IFTYPE}":"6"},{"{#SNMPINDEX}":"4","{#SNMPVALUE}":"2","{#IFADMINSTATUS}":"1","{#IFALIAS}":"","{#IFNAME}":"ether4-slave-local","{#IFDESCR}":"ether4-slave-local","{#IFTYPE}":"6"},{"{#SNMPINDEX}":"5","{#SNMPVALUE}":"2","{#IFADMINSTATUS}":"1","{#IFALIAS}":"","{#IFNAME}":"ether5-slave-local","{#IFDESCR}":"ether5-slave-local","{#IFTYPE}":"6"},{"{#SNMPINDEX}":"6","{#SNMPVALUE}":"2","{#IFADMINSTATUS}":"1","{#IFALIAS}":"","{#IFNAME}":"wlan1","{#IFDESCR}":"wlan1","{#IFTYPE}":"71"},{"{#SNMPINDEX}":"7","{#SNMPVALUE}":"1","{#IFADMINSTATUS}":"1","{#IFALIAS}":"","{#IFNAME}":"bridge-local","{#IFDESCR}":"bridge-local","{#IFTYPE}":"209"}]}'
Full scenario:
# install snmptrap
yum install -y net-snmp-utils net-snmp-perl net-snmp nmap

# Install allowed community names
cat <<'EOF'> /etc/snmp/snmptrapd.conf
authCommunity execute Earth
perl do "/usr/bin/zabbix_trap_receiver.pl";
EOF

# install perl trap parser
curl https://raw.githubusercontent.com/zabbix/zabbix/trunk/misc/snmptrap/zabbix_trap_receiver.pl > /usr/bin/zabbix_trap_receiver.pl
chmod +x /usr/bin/zabbix_trap_receiver.pl

systemctl enable snmptrapd
systemctl start snmptrapd
systemctl status snmptrapd

# send test trap
snmptrap -v 1 -c Earth 127.0.0.1 'IF-MIB::linkDown' '0.0.0.0' 6 33 '55' .1.3.6.1.6.3.1.1.5.3 s "wlan1"

# observe if the "wlan1" content is there
cat /tmp/zabbix_traps.tmp

# empty the file
> /tmp/zabbix_traps.tmp

# make sure the trap receiver is enabled in zabbix_server
grep SNMPTrapperFile= /etc/zabbix/zabbix_server.conf
grep StartSNMPTrapper= /etc/zabbix/zabbix_server.conf

# restart zabbix server
systemctl restart zabbix-server

# see if there is not errors inside
cat /var/log/zabbix/zabbix_server.log

# open host "Zabbix server"
# add new SNMP interfaces
# add template "generate snmp trap items from manual discovery"

# reload configuration cache
zabbix_server -R config_cache_reload

# send a fake discovery to create some interfaces
zabbix_sender -z 127.0.0.1 -s "Zabbix server" -k net.if.discovery.manual -o '{"data":[{"{#SNMPINDEX}":"1","{#SNMPVALUE}":"1","{#IFADMINSTATUS}":"1","{#IFALIAS}":"","{#IFNAME}":"ether1-gateway","{#IFDESCR}":"ether1-gateway","{#IFTYPE}":"6"},{"{#SNMPINDEX}":"2","{#SNMPVALUE}":"1","{#IFADMINSTATUS}":"1","{#IFALIAS}":"","{#IFNAME}":"ether2-master-local","{#IFDESCR}":"ether2-master-local","{#IFTYPE}":"6"},{"{#SNMPINDEX}":"3","{#SNMPVALUE}":"2","{#IFADMINSTATUS}":"1","{#IFALIAS}":"","{#IFNAME}":"ether3-slave-local","{#IFDESCR}":"ether3-slave-local","{#IFTYPE}":"6"},{"{#SNMPINDEX}":"4","{#SNMPVALUE}":"2","{#IFADMINSTATUS}":"1","{#IFALIAS}":"","{#IFNAME}":"ether4-slave-local","{#IFDESCR}":"ether4-slave-local","{#IFTYPE}":"6"},{"{#SNMPINDEX}":"5","{#SNMPVALUE}":"2","{#IFADMINSTATUS}":"1","{#IFALIAS}":"","{#IFNAME}":"ether5-slave-local","{#IFDESCR}":"ether5-slave-local","{#IFTYPE}":"6"},{"{#SNMPINDEX}":"6","{#SNMPVALUE}":"2","{#IFADMINSTATUS}":"1","{#IFALIAS}":"","{#IFNAME}":"wlan1","{#IFDESCR}":"wlan1","{#IFTYPE}":"71"},{"{#SNMPINDEX}":"7","{#SNMPVALUE}":"1","{#IFADMINSTATUS}":"1","{#IFALIAS}":"","{#IFNAME}":"bridge-local","{#IFDESCR}":"bridge-local","{#IFTYPE}":"209"}]}'
# see if output reports 'processed: 1;'

# reload configuration cache
zabbix_server -R config_cache_reload

# open latest data page, set application "trap regex", see if there is bunch of items

# send again trap
snmptrap -v 1 -c Earth 127.0.0.1 'IF-MIB::linkDown' '0.0.0.0' 6 33 '55' .1.3.6.1.6.3.1.1.5.3 s "wlan1"
Two variables - title and item:
zabbix_sender -z 127.0.0.1 -s $(hostname) -k lld.trap -o '{"data":[{"{#TITLE}": "fisrt","{#ITEM}": "long item name"},{"{#TITLE}":"second","{#ITEM}": "extra really long item name"}]}'
Long strings:
{"data":[{"{#N}":"You can directly input a URL into the editor and JSONLint will scrape it for JSON and parse it"},{"{#N}":"You can directly input a URL into the editor and JSONLint will scrape it for JSON and parse it As a solution either use direct URL input or make sure your contents newlines match the architecture your system expects"}]}

No comments: