[AGENT++] simple MibTable registration problem (with the AgentX++ master)
Razvan Cojocaru
razvan.cojocaru at kaspersky.ro
Fri Apr 6 14:01:23 CEST 2007
Funny stuff. Ok. Info follows:
----------------------- master log -----------------------------
20070406.14:36:10: 7132: (1)EVENT : main: SNMP listen port: (4700)
20070406.14:36:10: 7132: (3)DEBUG : MibContext: adding MIB object
(context)(oid): (), (1.3.6.1.2.1.74)
20070406.14:36:10: 7132: (3)DEBUG : MibContext: adding MIB object
(context)(oid): (), (1.3.6.1.2.1.1)
20070406.14:36:10: 7132: (3)DEBUG : MibContext: adding MIB object
(context)(oid): (), (1.3.6.1.2.1.11)
20070406.14:36:10: 7132: (3)DEBUG : MibContext: adding MIB object
(context)(oid): (), (1.3.6.1.6.3.1.1.6.1.0)
20070406.14:36:10: 7132: (3)DEBUG : MibContext: adding MIB object
(context)(oid): (), (1.3.6.1.6.3.12)
20070406.14:36:10: 7132: (3)DEBUG : MibContext: adding MIB object
(context)(oid): (), (1.3.6.1.4.1.4976.100.0)
20070406.14:36:10: 7132: (3)DEBUG : MibContext: adding MIB object
(context)(oid): (), (1.3.6.1.6.3.13.1)
20070406.14:36:10: 7134: (1)DEBUG : Thread: started (tid): (0)
20070406.14:36:10: 7132: (1)DEBUG : TaskManager: thread started
20070406.14:36:10: 7135: (1)DEBUG : Thread: started (tid): (0)
20070406.14:36:10: 7132: (1)DEBUG : TaskManager: thread started
20070406.14:36:10: 7132: (1)DEBUG : TaskManager: thread started
20070406.14:36:10: 7136: (1)DEBUG : Thread: started (tid): (49156)
20070406.14:36:10: 7137: (1)DEBUG : Thread: started (tid): (0)
20070406.14:36:10: 7132: (1)DEBUG : TaskManager: thread started
20070406.14:36:10: 7138: (1)DEBUG : Thread: started (tid): (0)
20070406.14:36:10: 7132: (1)DEBUG : TaskManager: thread started
20070406.14:36:10: 7139: (1)DEBUG : Thread: started (tid): (98311)
20070406.14:36:10: 7140: (1)DEBUG : Thread: started (tid): (0)
20070406.14:36:10: 7141: (1)DEBUG : Thread: started (tid): (0)
20070406.14:36:10: 7132: (1)DEBUG : TaskManager: thread started
20070406.14:36:10: 7142: (1)DEBUG : Thread: started (tid): (147466)
20070406.14:36:10: 7143: (1)DEBUG : Thread: started (tid): (0)
20070406.14:36:10: 7132: (1)DEBUG : TaskManager: thread started
20070406.14:36:10: 7144: (1)DEBUG : Thread: started (tid): (0)
20070406.14:36:10: 7132: (1)DEBUG : TaskManager: thread started
20070406.14:36:10: 7132: (1)DEBUG : TaskManager: thread started
20070406.14:36:10: 7132: (1)DEBUG : TaskManager: task manager found
20070406.14:36:10: 7132: (2)DEBUG : TaskManager: after notify
20070406.14:36:10: 7132: (4)DEBUG : SNMPMessage: return value for build
message: (0)
20070406.14:36:10: 7132: (1)EVENT : NotificationGenerator: sent v1 trap
(id)(tdomain)(addr)(vbs)(community): (1.3.6.1.6.3.1.1.5.1), (1),
(127.0.0.1/162), (0),
(public)
20070406.14:36:10: 7134: (1)EVENT : AgentX Master Agent starting
20070406.14:36:10: 7134: (1)INFO : AgentX: listening for AgentX
requests on UNIX (port): (/var/agentx/master)
20070406.14:36:10: 7134: (1)EVENT : AgentXMaster: listening on TCP
(socket)(port): (7), (705)
20070406.14:36:10: 7145: (1)DEBUG : Thread: started (tid): (196621)
20070406.14:36:28: 7134: (1)EVENT : AgentXMaster: accepting new connections
20070406.14:36:28: 7134: (1)EVENT : AgentXMaster: new subagent
connection on UNIX port
20070406.14:36:28: 7134: (4)EVENT : AgentXMaster: new peer added
(sd)(name)(connecttime)(timeout): (8), (1175859388), (5)
20070406.14:36:28: 7134: (5)DEBUG : MasterAgentXMib: reading AgentX packet
20070406.14:36:28: 7134: (4)DEBUG : MasterAgentXMib: processing AgentX
packet from (sd)(type): (8), (1)
20070406.14:36:28: 7134: (5)EVENT : MasterAgentXMib: opened new session
(id)(peer)(sessionCount): (1), (8), (1)
20070406.14:36:28: 7134: (3)DEBUG : MasterAgentXMib: sending response
(tid)(peer)(err): (0), (8), (0)
20070406.14:36:28: 7134: (3)EVENT : AgentX: sending agentx pdu
(sd)(type)(sid)(tid)(pid)(err)(errind): (8), (18), (1), (0), (1), (0), (0)
20070406.14:36:28: 7134: (2)EVENT : MasterAgentXMib: sent response
(tid)(peer)(uptime): (0), (8), (1738)
20070406.14:36:28: 7134: (5)DEBUG : MasterAgentXMib: reading AgentX packet
20070406.14:36:28: 7134: (4)DEBUG : MasterAgentXMib: processing AgentX
packet from (sd)(type): (8), (16)
20070406.14:36:28: 7134: (3)EVENT : MasterAgentXMib: adding agent caps
from (sid)(id)(descr): (1), (1.3.6.1.4.1.4976.4.1.1), (AGENT++ agent
built-in capabiliti
es)
20070406.14:36:28: 7134: (3)DEBUG : MasterAgentXMib: sending response
(tid)(peer)(err): (0), (8), (0)
20070406.14:36:28: 7134: (3)EVENT : AgentX: sending agentx pdu
(sd)(type)(sid)(tid)(pid)(err)(errind): (8), (18), (1), (0), (2), (0), (0)
20070406.14:36:28: 7134: (2)EVENT : MasterAgentXMib: sent response
(tid)(peer)(uptime): (0), (8), (1738)
20070406.14:36:28: 7134: (5)DEBUG : MasterAgentXMib: reading AgentX packet
20070406.14:36:28: 7134: (4)DEBUG : MasterAgentXMib: processing AgentX
packet from (sd)(type): (8), (3)
20070406.14:36:28: 7134: (1)DEBUG : TaskManager: task manager found
20070406.14:36:28: 7134: (2)DEBUG : TaskManager: after notify
20070406.14:36:28: 7135: (3)DEBUG : MasterAgentXMib: sending response
(tid)(peer)(err): (1), (8), (0)
20070406.14:36:28: 7135: (3)EVENT : AgentX: sending agentx pdu
(sd)(type)(sid)(tid)(pid)(err)(errind): (8), (18), (1), (1), (3), (0), (0)
20070406.14:36:28: 7135: (2)EVENT : MasterAgentXMib: sent response
(tid)(peer)(uptime): (1), (8), (1738)
20070406.14:36:28: 7135: (3)DEBUG : MibContext: adding MIB object
(context)(oid): (subagent), (1.3.6.1.2.1.1.3.0)
20070406.14:36:28: 7135: (2)EVENT : MasterAgentXMib: registered new
(context)(lower)(upper): (subagent), (1.3.6.1.2.1.1.3.0),
(1.3.6.1.2.1.1.3.1)
20070406.14:36:43: 7134: (5)DEBUG : MasterAgentXMib: reading AgentX packet
20070406.14:36:43: 7134: (4)DEBUG : MasterAgentXMib: processing AgentX
packet from (sd)(type): (8), (13)
20070406.14:36:43: 7134: (3)DEBUG : MasterAgentXMib: sending response
(tid)(peer)(err): (2), (8), (0)
20070406.14:36:43: 7134: (3)EVENT : AgentX: sending agentx pdu
(sd)(type)(sid)(tid)(pid)(err)(errind): (8), (18), (1), (2), (5), (0), (0)
20070406.14:36:43: 7134: (2)EVENT : MasterAgentXMib: sent response
(tid)(peer)(uptime): (2), (8), (3258)
20070406.14:36:43: 7134: (5)DEBUG : MasterAgentXMib: reading AgentX packet
20070406.14:36:43: 7134: (1)ERROR : AgentX: receive unknown error
(errno): (104)
20070406.14:36:43: 7134: (3)WARNING: MasterAgentXMib: lost connection
(sd)(err): (8), (-1)
20070406.14:36:43: 7134: (1)DEBUG : TaskManager: task manager found
20070406.14:36:43: 7134: (2)DEBUG : TaskManager: after notify
----------------------- master log -----------------------------
----------------------- subagent log ---------------------------
20070406.14:36:28: 7151: (3)DEBUG : MibContext: adding MIB object
(context)(oid): (subagent), (1.3.6.1.2.1.1.3.0)
20070406.14:36:28: 7151: (3)DEBUG : MibContext: adding MIB object
(context)(oid): (), (1.3.6.1.4.1.23668.1234.1.4.1.1)
20070406.14:36:28: 7153: (1)DEBUG : Thread: started (tid): (0)
20070406.14:36:28: 7151: (1)DEBUG : TaskManager: thread started
20070406.14:36:28: 7154: (1)DEBUG : Thread: started (tid): (0)
20070406.14:36:28: 7151: (1)DEBUG : TaskManager: thread started
20070406.14:36:28: 7155: (1)DEBUG : Thread: started (tid): (49156)
20070406.14:36:28: 7156: (1)DEBUG : Thread: started (tid): (0)
20070406.14:36:28: 7151: (1)DEBUG : TaskManager: thread started
20070406.14:36:28: 7157: (1)DEBUG : Thread: started (tid): (0)
20070406.14:36:28: 7151: (1)DEBUG : TaskManager: thread started
20070406.14:36:28: 7151: (1)DEBUG : TaskManager: thread started
20070406.14:36:28: 7151: (2)EVENT : SubAgentXMib: opening socket
20070406.14:36:28: 7151: (1)INFO : SubAgentX: bound local
(socket)(sd): (/var/agentx/subagent07151), (5)
20070406.14:36:28: 7151: (1)INFO : SubAgentX: connected local socket
with master (sd)(socket): (5), (/var/agentx/master)
20070406.14:36:28: 7151: (1)EVENT : SubAgentXMib: contacting master,
please wait
20070406.14:36:28: 7151: (3)EVENT : AgentX: sending agentx pdu
(sd)(type)(sid)(tid)(pid)(err)(errind): (5), (1), (0), (0), (1), (0), (0)
20070406.14:36:28: 7151: (4)DEBUG : AgentXSlave: received something on
ports
20070406.14:36:28: 7151: (5)DEBUG : AgentXSlave: received
(sd)(current)(stop)(status): (5), (-961650894), (-961645894), (0)
20070406.14:36:28: 7151: (1)INFO : AgentXSlave: opened session
(sid)(pid): (1), (0)
20070406.14:36:28: 7151: (1)EVENT : SubAgentXMib: connected - now
registering..
20070406.14:36:28: 7151: (1)DEBUG : TaskManager: task manager found
20070406.14:36:28: 7151: (2)DEBUG : TaskManager: after notify
20070406.14:36:28: 7151: (1)EVENT : SubAgentXMib: nodes registering...
20070406.14:36:28: 7151: (2)DEBUG : AgentXSlave: sending add agent caps
PDU (context)(id)(descr): (), (1.3.6.1.4.1.4976.4.1.1), (AGENT++ agent
built-in capabil
ities)
20070406.14:36:28: 7151: (3)EVENT : AgentX: sending agentx pdu
(sd)(type)(sid)(tid)(pid)(err)(errind): (5), (16), (1), (0), (2), (0), (0)
20070406.14:36:28: 7151: (4)DEBUG : AgentXSlave: received something on
ports
20070406.14:36:28: 7151: (2)EVENT : AgentXRequestList: request received
(context)(tid)(pid)(siz)(type)(err)(status): (), (0), (2), (0), (18),
(0), (0)
20070406.14:36:28: 7151: (1)DEBUG : TaskManager: task manager found
20070406.14:36:28: 7151: (2)DEBUG : TaskManager: after notify
20070406.14:36:28: 7155: (2)INFO : SubAgentXMib: registering shared
table rows (oid): (1.3.6.1.4.1.23668.1234.1.4.1.1)
20070406.14:36:28: 7155: (2)INFO : SubAgentXMib: registering node
(oid)(single): (1.3.6.1.2.1.1.3.0), (true)
20070406.14:36:28: 7155: (2)DEBUG : AgentXSlave: sending register PDU
(context)(oid)(rangeid)(upper): (subagent), (1.3.6.1.2.1.1.3.0), (0),
(1.3.6.1.2.1.1.3.0)
20070406.14:36:28: 7155: (3)EVENT : AgentX: sending agentx pdu
(sd)(type)(sid)(tid)(pid)(err)(errind): (5), (3), (1), (1), (3), (0), (0)
20070406.14:36:28: 7151: (4)DEBUG : AgentXSlave: received something on
ports
20070406.14:36:28: 7151: (2)EVENT : AgentXRequestList: request received
(context)(tid)(pid)(siz)(type)(err)(status): (), (1), (3), (0), (18),
(0), (0)
20070406.14:36:28: 7151: (1)DEBUG : TaskManager: task manager found
20070406.14:36:28: 7151: (2)DEBUG : TaskManager: after notify
20070406.14:36:28: 7156: (2)EVENT : SubAgent: starting thread execution
20070406.14:36:28: 7156: (1)DEBUG : TaskManager: task manager found
20070406.14:36:28: 7153: (1)DEBUG : SubAgentXMib: unhandled response
(tid)(pid): (0), (2)
20070406.14:36:28: 7156: (2)DEBUG : TaskManager: after notify
20070406.14:36:28: 7156: (2)EVENT : Agent: finished thread execution
20070406.14:36:28: 7157: (2)EVENT : SubAgent: starting thread execution
20070406.14:36:28: 7157: (1)DEBUG : TaskManager: task manager found
20070406.14:36:28: 7153: (1)DEBUG : SubAgentXMib: registration success
(oid): (1.3.6.1.2.1.1.3.0)
20070406.14:36:28: 7157: (2)DEBUG : TaskManager: after notify
20070406.14:36:28: 7157: (2)EVENT : Agent: finished thread execution
20070406.14:36:28: 7158: (1)DEBUG : Thread: started (tid): (98311)
----------------------- subagent log ---------------------------
----------------------- subagent code --------------------------
#include <iostream>
#include <signal.h>
#include <agent_pp/vacm_class.h>
#include <agent_pp/snmp_pp_ext.h>
#include <agent_pp/request.h>
#include <agent_pp/mib.h>
#include <agent_pp/system_group.h>
#include <agent_pp/snmp_group.h>
#include <agent_pp/snmp_target_mib.h> // traps stuff
#include <agent_pp/snmp_notification_mib.h> // traps stuff.
#include <agent_pp/notification_originator.h> // traps stuff.
#include <agent_pp/mib_complex_entry.h>
#include <agent_pp/v3_mib.h>
#include <snmp_pp/oid_def.h>
#include <snmp_pp/mp_v3.h>
#include <agentx_pp/agentx_subagent.h>
#ifdef AGENTPP_NAMESPACE
using namespace Agentpp;
#endif
#ifdef SNMP_PP_NAMESPACE
using namespace Snmp_pp;
#endif
using namespace std;
bool run = true;
//! An Agent++ SNMP Mib table class (i.e. a configuration group)
class MyTable : public MibTable {
public:
//! Constructor
MyTable();
//! Virtual override - implements data retrieval upon request
void update(Request* req);
private:
//! Internal cookie for row generation
unsigned long currentRequest_;
};
MyTable::MyTable()
: MibTable("1.3.6.1.4.1.23668.1234.1.4.1.1"), currentRequest_(0)
{
add_col(new MibLeaf("1", READWRITE, new SnmpInt32(0)));
add_col(new MibLeaf("2", READWRITE, new OctetStr("")));
add_col(new MibLeaf("3", READWRITE, new OctetStr("")));
}
void MyTable::update(Request* req)
{
// we can get called for each item so only do hard work when a
// brand new request is being performed.
if(currentRequest_ == req->get_request_id())
return;
currentRequest_ = req->get_request_id();
start_synch(); // begin transaction
MibTableRow *row = add_row("1");
row->get_nth(0)->replace_value(new SnmpInt32(1));
row->get_nth(1)->replace_value(new OctetStr("1str1"));
row->get_nth(2)->replace_value(new OctetStr("1str2"));
row = add_row("2");
row->get_nth(0)->replace_value(new SnmpInt32(2));
row->get_nth(1)->replace_value(new OctetStr("2str1"));
row->get_nth(2)->replace_value(new OctetStr("2str2"));
end_synch(); // end transaction
}
static void sig(int signo)
{
if ((signo == SIGTERM) || (signo == SIGINT) || (signo == SIGSEGV)) {
printf ("\n");
switch (signo) {
case SIGSEGV: {
printf ("Segmentation fault, aborting.\n");
exit(1);
}
case SIGTERM:
case SIGINT: {
if (run) {
run = false;
printf ("User abort\n");
}
}
}
}
}
void init_signals()
{
signal (SIGTERM, sig);
signal (SIGINT, sig);
signal (SIGSEGV, sig);
}
void snmp_mib_init_agentx(Mib& mib)
{
// add a static table to the "subagent" context
mib.add("subagent", new sysUpTime());
mib.add(new MyTable());
}
int main()
{
Mib* mib = 0;
RequestList* reqList = 0;
AgentXSlave* agentx = 0;
mib = new SubAgentXMib();
//Set the default priority for registrations by this sub-agent.
static_cast<SubAgentXMib*>(mib)->set_default_priority(100);
agentx = new AgentXSlave();
#ifdef AX_UNIX_SOCKET
agentx->set_unix_port_loc("/var/agentx/");
agentx->set_connect_mode(AX_USE_UNIX_SOCKET | AX_USE_TCP_SOCKET);
#else
agentx->set_connect_mode(AX_USE_TCP_SOCKET);
#endif
reqList = new AgentXRequestList(agentx);
static_cast<SubAgentXMib*>(mib)->set_request_list(static_cast<AgentXRequestList*>(reqList));
snmp_mib_init_agentx(*mib);
init_signals();
if(!mib->init()) {
cerr << "FAILED to init MIB";
exit(1);
}
// add agent caps *after* connection is up
mib->add_agent_caps("", "1.3.6.1.4.1.4976.4.1.1",
"AGENT++ agent built-in capabilities");
// MAIN loop
Request* req = NULL;
while ((run) &&
(!static_cast<SubAgentXMib*>(mib)->get_agentx()->quit())) {
req = reqList->receive(20000);
if (req)
mib->process_request(req);
else {
// ping the master
static_cast<SubAgentXMib*>(mib)->ping_master();
}
}
return 0;
}
/*
Local Variables:
mode: c++
c-basic-offset: 4
tab-width: 4
c-indent-comments-syntactically-p: t
indent-tabs-mode: nil
End:
*/
// vim:shiftwidth=4:autoindent:tabstop=4:expandtab:softtabstop=4
----------------------- subagent code --------------------------
The static_casts<> were preserved from the Agent/AgentX flexible code.
Some code has been quickly pulled out, thus resulting in potential
memory leaks. But it should be OK as far as a proof of concept minimal
sample goes.
--
Razvan Cojocaru
KeyID: 1024D/04CA34DE
More information about the AGENTPP
mailing list