Nagios SNMP v3 on HP Procurve 2910 - snmp

I'm having trouble getting the check_snmp plugin to connect and return values. I'm running CentOS7, Nagios 4.0.8, check_snmp 2.0.3. While can snmpget and snmpwalk from the command line, check_snmp fails. Here are some examples...
snmpget:
# snmpget -v 3 -u myuser -x aes -X mypasswd -a md5 -A mypasswd -c Public -l AuthPriv 111.222.333.111 sysUpTime.0
...returns...
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (10475998) 1 day, 5:05:59.98
snmpwalk:
# snmpwalk -v 3 -u myuser -x aes -X mypasswd -a md5 -A mypasswd -c Public -l AuthPriv 111.222.333.111 sysUptime
...returns...
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (10473493) 1 day, 5:06:10.93
check_snmp:
/usr/lib64/nagios/plugins/check_snmp -H 111.222.333.111 -o sysUpTime.0 -P 3 -l AuthPriv -U myuser -A mypasswd -a md5 -X mypasswd -x aes
...returns...
External command error: Error in packet
Reason: authorizationError (access denied to that object)
Failed object: DISMAN-EVENT-MIB::sysUpTimeInstance
When I run check_snmp with verbose on, I get...
/usr/bin/snmpget -Le -t 1 -r 5 -m ALL -v 3 [authpriv] 156.128.2.250:161 sysUpTime.0
check_snmp is clearly not constructing the snmpget command with the args that are being passed to it. I'm at a loss for why.

The syntax is a little different for check_snmp sec level. Try:
-L authPriv
instead of:
-l AuthPriv
You can confirm this by invoking the help of the plugin with -h:
./check_snmp -h
check_snmp v2.0.3 (nagios-plugins 2.0.3)
...
-L, --seclevel=[noAuthNoPriv|authNoPriv|authPriv]
...

Related

Subscribe and Publish in BASH like a receive Buffer

I want to buffer all messages of a subscription during processing publish messages.
The reason is a firmware update over MQTT. I want to send data with crc and the microcontroller have to verify the content and need to answer with new address pointer.
For now, i got it working without any interaction from the microcontroller. If size doesn't fit, or mc is not online, my bash script sends all the data of the binary file into the nirvana.
If I publish a message and subscribe directly after the publish, it is possible to lose an answer very easily.
But I'm not so experienced with bash and I need some suggestions how to do this...
This is what I have:
mosquitto_pub -h $MQTT_SERVER -t "spiffs/${client_name}/file_info" -m "$binary_file" -p 8883 -i "fw_server" --cafile server-cert.pem -d --insecure -u $MQTT_USER -P $MQTT_PW
mosquitto_sub -h $MQTT_SERVER -p 8883 -t "+/${client_name}/#" -i "fw_server" --cafile server-cert.pem -d --insecure -u $MQTT_USER -P $MQTT_PW | while read -r payload
do
fp_jq_rspCode=".upload.fp" # file pointer
address=$(echo $payload | jq -r $fp_jq_rspCode)
echo "${payload}" | jq -c '.[]'
echo "address pointer:$address"
c=${address}
addr=$(printf '%08x' "$c")
content=$(xxd -p -c $payload_size -l $payload_size -seek $c $binary_file)
length=`expr length "$content"`
len=$(printf '%04x' "$length")
crc32=$(echo -n "$content" | gzip -c | tail -c8 | hexdump -n4 -e '"%u"')
crc32=$(printf '%08x' "$crc32")
echo "$addr $len $content $crc32"
message=$(printf '%08x%04x%s%s' "$c" "$length" "$content" "$crc32")
mosq=$(mosquitto_pub -h $MQTT_SERVER -t "spiffs/${client_name}/upload" -m "$message" -p 8883 -i "fw_server" --cafile server-cert.pem -d --insecure -u $MQTT_USER -P $MQTT_PW)
done

Weird output observed on executing ssh commands remotely over ProxyCommand

Team, I have two steps to perform:
SCP a shell script file to remote ubuntu linux machine
Execute this uploaded file on remote ubuntu linux machine over SSH session using PROXYCommand because I have bastion server in front.
Code:
scp -i /home/dtlu/.ssh/key.key -o "ProxyCommand ssh -i /home/dtlu/.ssh/key.key lab#api.dev.test.com -W %h:%p" /home/dtlu/backup/test.sh lab#$k8s_node_ip:/tmp/
ssh -o StrictHostKeyChecking=no -i /home/dtlu/.ssh/key.key -o 'ProxyCommand ssh -i /home/dtlu/.ssh/key.key -W %h:%p lab#api.dev.test.com' lab#$k8s_node_ip "uname -a; date;echo "Dummy123!" | sudo -S bash -c 'echo 127.0.1.1 \`hostname\` >> /etc/hosts'; cd /tmp; pwd; systemctl status cachefilesd | grep Active; ls -ltr /tmp/test.sh; echo "Dummy123!" | sudo -Sv && bash -s < test.sh"
Both calls above are working fine. I am able to upload test.sh and also its running but what is bothering me is during the process am observe weird output being thrown out.
output:
/tmp. <<< expected
[sudo] password for lab: Showing one
Sent message type=method_call sender=n/a destination=org.freedesktop.DBus object=/org/freedesktop/DBus interface=org.freedesktop.DBus member=Hello cookie=1 reply_cookie=0 error=n/a
Root directory /run/log/journal added.
Considering /run/log/journal/df22e14b1f83428292fe17f518feaebb.
Directory /run/log/journal/df22e14b1f83428292fe17f518feaebb added.
File /run/log/journal/df22e14b1f83428292fe17f518feaebb/system.journal added.
So, I don't want /run/log/hournal and other lines which don't correspond to my command in sh.
Consider adding -q to the scp and ssh commands to reduce the output they might produce. You can also redirect stderr and stdout to /dev/null as appropriate.
For example:
{
scp -q -i /home/dtlu/.ssh/key.key -o "ProxyCommand ssh -i /home/dtlu/.ssh/key.key lab#api.dev.test.com -W %h:%p" /home/dtlu/backup/test.sh lab#$k8s_node_ip:/tmp/
ssh -q -o StrictHostKeyChecking=no -i /home/dtlu/.ssh/key.key -o 'ProxyCommand ssh -i /home/dtlu/.ssh/key.key -W %h:%p lab#api.dev.test.com' lab#$k8s_node_ip "uname -a; date;echo "Dummy123!" | sudo -S bash -c 'echo 127.0.1.1 \`hostname\` >> /etc/hosts'; cd /tmp; pwd; systemctl status cachefilesd | grep Active; ls -ltr /tmp/test.sh; echo "Dummy123!" | sudo -Sv && bash -s < test.sh"
} >&/dev/null

mosquitto_pub Error: '-l' mode not available threading support has not been compiled in

When trying to publish a message to a topic using the mosquitto_pub -l flag, I get the error:
Error: '-l' mode not available, threading support has not been compiled in.
How can I correct this?
For reference mosquitto_pub is version 1.5.3, running on libmosquitto 1.5.3., and the command I am trying to run is:
mosquitto_pub -h <hostname> -p <port> -t "<topic>" --cafile /usr/local/etc/openssl/cert.pem -d -P "$(cat mqtt-token-pub.txt)" -u <username> -l
Note: it works if I use -m "blah" instead of -l

Ldap search with negative parameter

I'm trying to do a search on my LDAP base like that:
ldapsearch -x -h localhost -p 389 -D uid=xxxadmin,ou=administrators,ou=topologymanagement,o=netscaperoot -v -w 12345 -b "ou=Usuarios,ou=Alunos,ou=XXXX,o=xxXXXxx" -f (!(objectClass=ntUser)) 1.1
Basically I want to list all the entries without the objectClass ntUser and add the objectClass to them.
I'm getting this as an answer:
-bash: !: event not found
From http://www.openldap.org/lists/openldap-software/200104/msg00196.html
This message comes from the shell (bash). It states that the command
`!' didn't find the event you unintentionally asked for. This happens
because the double quotes in bash do not prevent some command
invocation. Use single quotes instead:
Your search should be like this:
ldapsearch -x -h localhost -p 389 -D 'uid=xxxadmin,ou=administrators,ou=topologymanagement,o=netscaperoot' -v -w 12345 -b 'ou=Usuarios,ou=Alunos,ou=XXXX,o=xxXXXxx' -f '(!(objectClass=ntUser))' 1.1
Your search should work. But, for bash, you will need to quote the parameters.
Something like:
ldapsearch -x -h localhost -p 389 -D uid=xxxadmin,ou=administrators,ou=topologymanagement,o=netscaperoot -v -w 12345 -b "ou=Usuarios,ou=Alunos,ou=XXXX,o=xxXXXxx" -f "(!(objectClass=ntUser))" 1.1
Tested both openLDAP
#(#) $OpenLDAP: ldapsearch (Ubuntu) (Mar 17 2014 21:19:27) $buildd#aatxe:/build/buildd/openldap-2.4.31/debian/build/clients/tools
(LDAP library: OpenLDAP 20431)
ldapsearch -x -h localhost -p 389 -D "cn=admin" -W -b "dc=example,dc=com" -s sub -a always -z 1000 "(!(objectClass=inetOrgPerson))" "objectClass"
and OpenDJ
ldapsearch --version
OpenDJ 2.7.0-20140727
Build 20140727000040Z
ldapsearch -h localhost -p 389 -D "cn=admin" -b "dc=example,dc=com" -s sub -a always -z 1000 "(!(objectClass=inetOrgPerson))" "objectClass"
-jim
Its happening because bash thinks ! as a special character
"!" Start a history substitution, except when followed by a space, tab, the end of the line, ‘=’ or ‘(’
So finally, you should be able to solve your problem by putting single quotes around the term as follow:
ldapsearch -x -h localhost -p 389 -D uid=xxxadmin,ou=administrators,ou=topologymanagement,o=netscaperoot -v -w 12345 -b "ou=Usuarios,ou=Alunos,ou=XXXX,o=xxXXXxx" -f '(!(objectClass=ntUser))' 1.1
Please refer following question on stackoverflow.
Which characters need to be escaped in Bash? How do we know it?

how to capture trap message in net-snmp

i work with net-snmp and i try a few commands like:
snmptrap -v 1 -c public host TRAP-TEST-MIB::demotraps localhost 6 17 '' \
SNMPv2-MIB::sysLocation.0 s "Just here"
snmptrap -v 2c -c public localhost '' NOTIFICATION-TEST-MIB::demo-notif \
SNMPv2-MIB::sysLocation.0 s "just here"
snmptrap -v 1 -c public host NET-SNMP-EXAMPLES-MIB::netSnmpExampleHeartbeatNotification "" 6 17 "" \
netSnmpExampleHeartbeatRate i 123456
but is just give me a new line without error or something
someone can give me advice ?
Netsnmp provides Snmptrapd for this purpose.
It is an application which can listen on a port (default 162) on a host for traps and will log those that are received.
//EDIT ...
Here is an example ...
snmptrapd -f -m +ALL -Lo -c /tmp/snmptrapd.conf 9876
where /tmp/snmptrapd.conf only contains one line which for simplicity disables community/password checking
disableAuthorization yes
Use man snmptrapd to see what the flags/arguements mean.

Resources