What sets SNMP error and error-index fields - snmp

I have read several RFCs about the SNMP protocol, and they are usually written in cryptic and opaque style, so I have probably missed the proper information and I apologize in advance for what is probably a simple question...
I am unclear about what kind of error in a get command for instance would set the error and error index fields in the snmp get-response message. Since I have been using Net-SNMP to send commands (and the snmp simulator at demo.snmplabs.com), I have not been able to send improperly formatted messages to see what kind of response I would get. I have started writing my own SNMP test tool (in Visual Basic) just to be able to send improperly formatted messages but it will be a fair amount of work before I can use it as a validated test tool.
When sending requests for non-existing OIDs or with wrong data type, it appears that Net-SNMP handles the errors without needing error/error-index values.
Any suggestion appreciated

It should be possible to generate errors for SNMP GETs but perhaps easier to start with generating errors for SETs.
➜ snmpset -v 2c -c private demohost sysName.0 s "foo"
SNMPv2-MIB::sysName.0 = STRING: foo
In version below agent rejects the SET...
➜ snmpset -v 2c -c private demohost ucdDemoPublicString.0 s "TEST"
Error in packet.
Reason: noCreation (That table does not support row creation or that object can not ever be created)
Failed object: UCD-DEMO-MIB::ucdDemoPublicString.0
Use -d to see the packets back and forth.

Related

SNMP GET snmpexception when response in V1 has trailing data bytes when using SharpSnmp

A SharpSnmpLib SNMP V1 GET snmpexception is thrown when querying a certain vendor equipment located in remote networks. Other software like iReasoning MIB Browser, SNMPB, or SnmpSharpNet work OK on the same OID and equipment.
The error varies even though the equipment is the same and the OID the same but located in a different network. It seems like a Data segment is added to the end of the UDP packet. One one piece of equipment the error message might be: "BER end of file", and on another identical piece of equipment, the error message is "unsupported data type:34", or "unsupported data type:115" and so on. Many different data types found on the same OID but from different pieces of equipment.
The error occurs in the project source file "MessageFactory.cs" in the ParseMessage routine. If I catch the error and continue the program works OK. I ignore the error for the trailing portion of data bytes that are not properly parsed.
The wireshark packets are also shown below:
And here is another error on another piece of exact same SNMP device and OID, just different IP address.
It seems like the trailing Data portion causes the API to throw an error because it does not recognize it as valid variable. Yet other software packages handle this without seeming error messages. I will have to modify the source code for Sharp SNMP to use the API unless finding a better solution. My modification involves catching the error and moving on. The first variable in the loop is already found and produces the proper value. The error occurs when continuing on from the first variable because the stream has not reached the end.
use the form that has (message, start, length, registry)
this works because it only reads from start to length and not the trailing problems

custom mib for postgresql in SNMP Trap in python

i want to send snmp trap using pysnmp library for database(postgresql). like when database goes down send a trap, similarly for when database goes up send another trap.
so now my question is how to define or create my own MIB file for the same in python.
thanks in advance
You may not absolutely require a MIB if all you want to do is to send SNMP TRAP. But I do not really know your requirements. Why do you think you need a MIB? Is it that you run some sort of NMS on the receiving side that requires MIB to analyse the event?
What you could do without MIB is to chose TRAP message contents that sufficiently describe the event using just OID-value pairs (e.g. required TRAP message contents + possibly OID-value pairs), then have the receiver of the TRAP analyse it accordingly.
If you still need a MIB, then you could just create one in your text editor. Take one of the existing MIBs as an example. You may test-compile it with mibdump.py to catch possible syntax errors. Once you are done, refer pysnmp to your TRAP object in the MIB so pysnmp which would compile and use it.

Bosun adding external collectors

What is the procedure to define new external collectors in bosun using scollector.
Can we write python or shell scripts to collect data?
The documentation around this is not quite up to date. You can do it as described in http://godoc.org/bosun.org/cmd/scollector#hdr-External_Collectors , but we also support JSON output which is better.
Either way, you write something and put it in the external collectors directory, followed by a frequency directory, and then an executable script or binary. Something like:
<external_collectors_dir>/<freq_sec>/foo.sh.
If the directory frequency is zero 0, then the the script is expected to be continuously running, and you put a sleep inside the code (This is my preferred method for external collectors). The scripts outputs the telnet format, or the undocumented JSON format to stdout. Scollector picks it up, and queues that information for sending.
I created an issue to get this documented not long ago https://github.com/bosun-monitor/bosun/issues/1225. Until one of us gets around to that, here is the PR that added JSON https://github.com/bosun-monitor/bosun/commit/fced1642fd260bf6afa8cba169d84c60f2e23e92
Adding to what Kyle said, you can take a look at some existing external collectors to see what they output. here is one written in java that one of our colleagues wrote to monitor jvm stuff. It uses the text format, which is simply:
metricname timestamp value tag1=foo tag2=bar
If you want to use the JSON format, here is an example from one of our collectors:
{"metric":"exceptional.exceptions.count","timestamp":1438788720,"value":0,"tags":{"application":"AdServer","machine":"ny-web03","source":"NY_Status"}}
And you can also send metadata:
{"Metric":"exceptional.exceptions.count","Name":"rate","Value":"counter"}
{"Metric":"exceptional.exceptions.count","Name":"unit","Value":"errors"}
{"Metric":"exceptional.exceptions.count","Name":"desc","Value":"The number of exceptions thrown per second by applications and machines. Data is queried from multiple sources. See status instances for details on exceptions."}`
Or send error messages to stderror:
2015/08/05 15:32:00 lookup OR-SQL03: no such host

What is the second paramenter of TCPSocket.send in Ruby?

I am using this line to send a message via a Ruby (1.8.7) socket:
##socket.send login_message, 0
(This works fine)
What is the second parameter for? I can't find the send method in the Ruby API docs...
I first thought that it was some C style length of the message. This is why I used login_message.length as second parameter. That worked but I encountered a strange behavior:
Everything works fine when the second parameter is a odd number. If it's an even number the last character gets lost at receiving on the other side (The other side is a C++ program with a C socket). I inspected the network traffic with Wireshark and noticed that the packets look good. All the data is complete. Why is the last character lost when I receive it?
Thank you
Lennart
This is the flags parameter, the same as the last parameter to the send() system call. Normally it should be 0, but may be something like Socket::MSG_OOB (to send out-of-band data). For Ruby 1.9 this is documented under BasicSocket.

When deleting SMS, they don't get deleted

I connected a GSM/GPRS-modem to my microcontroller and everything works fine.
When I want to delete all messages in the ME storage, I should use this command:
AT+CMGD=1,4
->OK
The deleteflag '4' indicates that I want to delete all messages and flag '1' is overridden. However, when I check if the storage is empty, I get:
AT+CPMS?
+CPMS: 8,100,8,100,8,100
Indicating that the memory is still occupied and no message got deleted.
Does anyone know what I'm doing wrong?
Thanks in advance!
I use the CMGD command to delete messages.
As far as I can see the CMGR command is used to read messages and not delete them.
Edit (since you were using the CMGD command)
It is possible that your modem doesn't support multiple parameters to the CMGD command - my Siemens modem does not (or if it does it doesn't list it in the AT command set document). Instead of deleting all the messages in a single command I do a CMGL to get read messages, parse the results to get the index and them delete them one at a time using CMGD. If you do find another way I'd be interested.
Use the AT+CMGD=? command to find valid values of the parameters.
Edit (since you verified the modem supports CMGD with two parameters
I don't know what the problem is.
I did notice that your CPMS command gives different results to mine, example of mine:
AT+CPMS?
+CPMS: "SM",10,10,"MT",12,35,"MT",12,35
Yours doesn't have any storage memory string. I'm guessing the command you actually did was:
AT+CPMS="ME"
When you switch to ME storage and do a CMGL command does it list the undeleted messages?
Try to set memory to ME using "AT+CPMS="ME"" and then retry your delete command with flag=4. I guess it will work. It not then run "AT+CSAS" to save the earlier setting and the retry delete. I could not test it as there is no SMS in my ME storage area. Let me know if it worked.

Resources