0

I follow this tutorial. I success to do all , but i cannot figure out how to change the MIB scalar value from my application.

I want to write values from my application to these OID in order to have the ability to monitor my application by SNMP.

the tutorial show you how to register an OID and set value to it, but how do i change the value from my application based on application state?

My goal: I have my own application (simple business application) that run on Ubuntu machine. I monitor the hosting machine from a remote client by SNMP . I monitor things like CPU , RAM .. I do this by send snmp-get to these OID.

As part of the hosting monitoring i want to monitor my application too (for example request_quoue_size), so i tought that the way to do this is by write my own MIB module and write call to set from my app on this OID, i am looking now how to call set (c++) and if this is the way.

Avihai Marchiano
  • 3,837
  • 3
  • 38
  • 55

1 Answers1

3

First of all MIB is only an interface (it specifies all the OIDs accessible from the MIB module). Is your application the SNMP agent or SNMP consumer?

If you are within SNMP agent then I assume you have a direct access to the memory, where OID is located. So, what is your problem exactly?

If you are within SNMP client then you need to send snmp-set request to the agent using proper UDP packet...

Please add some details on what you are trying to achieve.

lucassm
  • 319
  • 1
  • 6
  • Ok, I assume you are using NET-SNMP framework (written purely in C). If you want to build and send proper UDP packet for set-request then I recommend to take a look into snmpset.c file located in net-snmp-/snmp/agent/ directory. There you have a nice way how to write this functionality. Please note that there is also a possibility that you wrongly add a MIB module or scalar (is it read-write?) - just use snmp-set binary in your Ubuntu to perform set-request on that MIB to see if it works. If it does then you can start thinking of adding set-request code to your app. – lucassm Aug 27 '12 at 14:08
  • Am i doing correct? is this the way to be able to monitor my app ? i look on the file , this is their snmpset parser . i will try to mock it. i thought that they have a simple C API. – Avihai Marchiano Aug 27 '12 at 14:14
  • My understanding is that SNMP agent and application you're monitoring work on that same machine. Application you want to monitor needs to update data hidden behind the MIB scalar (it would be the best; other possibilities are also feasible). SNMP agent has to manage requests for registered MIB modules. If your MIB module and scalar object has been registered/defined correctly, then it should work. You can check it by sending from your machine a set-request using NET-SNMP tool called __snmpset__, i.e.: `snmpset -v1 -cprivate :161 = `. Could you show me your scalar definition? – lucassm Aug 27 '12 at 14:28
  • I dont know much about agents... i just want to have simple scalar (request_quoue_size) that can be monitoring from remote by snmpget. I might taking the wrong path or complex path in order to achieve that (so please correct me if i did wrong) i follow the tutorial in in the link. write my own mib module like explain in the link (just demo now). set by command line to this OID work. but know i want simple C API to change the value. – Avihai Marchiano Aug 27 '12 at 14:38
  • Assuming that you have correctly define and register that scalar in SNMP agent (in other words, agent knows that OID and understand the syntax, which is the way how value shall be encoded/decoded), then please use the code from snmpset.c. There and in header files used you will find the C API you're requesting. Other - simpler, but not so nice approach - is to call snmpset/snmpget shell command from your C/C++ application as a system call and put the command output to the file for parsing routine... – lucassm Aug 27 '12 at 17:48
  • Quote - "There and in header files used you will find the C API you're requesting." . There is no header file. so i will call to the shell command. – Avihai Marchiano Aug 28 '12 at 07:09