// this routine makes up the brains of the agent // it knows only the MIB II system group set of variables for a get operation int agent_impl::get_response(Vb& vb) { // these objects represent the MIB II system group per RFC 1213 static Oid sysDescr("1.3.6.1.2.1.1.1.0"), sysObjectID("1.3.6.1.2.1.1.2.0"), sysUpTime("1.3.6.1.2.1.1.3.0"), sysContact("1.3.6.1.2.1.1.4.0"), sysName("1.3.6.1.2.1.1.5.0"), sysLocation("1.3.6.1.2.1.1.6.0"), sysServices("1.3.6.1.2.1.1.7.0"); Oid oid; vb.get_oid(oid); if (oid == sysDescr) { OctetStr desc("ASNMP Prototype Agent 1.0"); vb.set_value(desc); } else if (oid == sysObjectID) { // the IANA gives assigns Enterprise Numbers // see ftp://ftp.isi.edu/in-notes/iana/assignments/enterprise-numbers // for the official list of enterprise numbers. Then under this tree // assign a unique subtree to identify this agent Oid id("1.3.6.1.4.1.2533.9.1"); vb.set_value(id); } else if (oid == sysUpTime) { ACE_Time_Value tv; agent_clock_.elapsed_time (tv); TimeTicks tt(tv.msec()); vb.set_value(tt); } else if (oid == sysContact) { OctetStr contact("*****@*****.**"); vb.set_value(contact); } else if (oid == sysName) { OctetStr fqdn("foo.org"); // extract this from the gethostbyname() TODO vb.set_value(fqdn); } else if (oid == sysLocation) { OctetStr loc(""); vb.set_value(loc); } else if (oid == sysServices) { SnmpInt32 svcs(72); vb.set_value(svcs); } else return 1; // noSuchName return 0; }
void mrbig(void) { char *p; time_t t, lastrun; int sleeptime, i; char hostname[256]; DWORD hostsize; /* * install exception logging/stacktrace handler. * We need to resolve the symbol at run time because windows 2000 * does not have it. */ do { HMODULE dll; PVOID (*ptr) (ULONG First,PVECTORED_EXCEPTION_HANDLER Handler) = NULL; dll = LoadLibraryEx("kernel32.dll", NULL, 0); if (dll == NULL) break; ptr = (typeof(ptr))GetProcAddress(dll, "AddVectoredExceptionHandler"); if (ptr == NULL) break; ptr(1, VectoredExceptionHandler); mrlog("VectoredExceptionHandler handler has been installed"); } while(0); if (debug) { mrlog("mrbig()"); } for (i = 0; _environ[i]; i++) { startup_log("%s", _environ[i]); } for (;;) { if (debug) mrlog("main loop"); read_cfg("mrbig", cfgfile); readcfg(); t = time(NULL); strlcpy(now, ctime(&t), sizeof now); p = strchr(now, '\n'); if (p) *p = '\0'; hostsize = sizeof hostname; if (GetComputerName(hostname, &hostsize)) { for (i = 0; hostname[i]; i++) hostname[i] = tolower(hostname[i]); snprcat(now, sizeof now, " [%s]", hostname); } cpu(); check_chunks("after cpu test"); disk(); check_chunks("after disk test"); memory(); check_chunks("after memory test"); msgs(); check_chunks("after msgs test"); procs(); check_chunks("after procs test"); svcs(); check_chunks("after svcs test"); wmi(); check_chunks("after wmi test"); if (pickupdir[0]) ext_tests(); lastrun = t; t = time(NULL); if (t < lastrun) { mrlog("mainloop: timewarp detected, sleep for %d", mrloop); sleeptime = mrloop; } else { sleeptime = mrloop-(t-lastrun); } if (sleeptime < SLEEP_MIN) sleeptime = SLEEP_MIN; if (debug) mrlog("started at %d, finished at %d, sleep for %d", (int)lastrun, (int)t, sleeptime); clear_cfg(); if (debug) { dump_chunks(); check_chunks("after main loop"); } Sleep(sleeptime*1000); } }