0

This tutorial explains how to send a SNMP TRAP calling send_v2trap() in C.

How do I send a SNMP INFORM instead? The manpage says I can send INFORMs, but it doesn't say how.

lseki
  • 351
  • 6
  • 21

2 Answers2

0

Figured out by myself :-)

send_v2trap(3) says:

send_v2trap() uses the supplied list of variable bindings to form an SNMPv2 trap,
which is sent to SNMPv2-capable sinks on the configured list.
An equivalent INFORM is sent to the configuredq list of inform sinks.

but doesn't say what is this configured list;

Instead, snmpd.conf(5) explains that I should edit /etc/snmp/snmpd.conf and add lines telling which hosts will receive the INFORMs. For example, the following makes send_v2trap() send INFORM to host1 and host2:

informsink host1 public 162
informsink host2 public 162
lseki
  • 351
  • 6
  • 21
0

Actually, you can register the sinks inside C by using the net-snmp, agent_trap.h function:

void            snmpd_parse_config_informsink(const char *, char *);

where I suppose that the first argument is not used and the second argument you can write as the following example in C++:

//sink declarations
String serverAddress = "127.0.0.1";
int serverPort = 162;
String community = "public";

//mount sink string 
string cptrS = serverAddress + ":" + to_string(serverPort)  + " \t\n" + community; 

//transform string to char*
char * cptr = &cptrS[0]; 

//register the sink 
snmpd_parse_config_informsink(NULL,cptr);

now, you can call send_v2trap() and send by inform the variables set using snmp_varlist_add_variable().

Reference: http://www.net-snmp.org/dev/agent/agent__trap_8c-source.html