0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

playing with net-snmp SERVER-120

This commit is contained in:
Eliot Horowitz 2009-11-06 16:27:49 -05:00
parent 2364528abf
commit dfda4ccc39
4 changed files with 160 additions and 3 deletions

View File

@ -185,6 +185,13 @@ AddOption( "--pg",
nargs=0,
action="store" )
AddOption( "--snmp",
dest="snmp",
type="string",
nargs=0,
action="store" )
# --- environment setup ---
def removeIfInList( lst , thing ):
@ -230,7 +237,7 @@ usesm = not GetOption( "usesm" ) is None
usev8 = not GetOption( "usev8" ) is None
usejvm = not GetOption( "usejvm" ) is None
enableSNMP = False
enableSNMP = GetOption( "snmp" ) is not None
env = Environment( MSVS_ARCH=msarch , tools = ["default", "gch"], toolpath = '.' )
if GetOption( "cxx" ) is not None:
@ -735,14 +742,15 @@ def doConfigure( myenv , needJava=True , needPcre=True , shell=False ):
gotAll = True
for x in snmplibs:
if not myCheckLib:
if not myCheckLib(x):
gotAll = False
if gotAll:
myenv.Append( CPPDEFINES=[ "_HAVESNMP" ] )
global serverOnlyFiles
serverOnlyFiles += [ "db/snmp.cpp" ]
else:
for x in snmplibs:
removeIfInList( myenv["LIBS"] , x )
# this is outside of usesm block so don't have to rebuild for java
if windows:

View File

@ -38,6 +38,9 @@
#include "../scripting/engine.h"
#include "mms.h"
#ifdef _HAVESNMP
#include "snmp.h"
#endif
#include "cmdline.h"
namespace mongo {
@ -425,6 +428,9 @@ namespace mongo {
_oplog.init();
mms.go();
#ifdef _HAVESNMP
snmpAgent.go();
#endif
#if 0
{
@ -561,6 +567,9 @@ int main(int argc, char* argv[], char *envp[] )
( "mms-token" , po::value<string>() , "account token for mongo monitoring server" )
( "mms-name" , po::value<string>() , "server name mongo monitoring server" )
( "mms-interval" , po::value<int>()->default_value(30) , "ping interval for mongo monitoring server" )
#ifdef _HAVESNMP
( "snmp-subagent" , "run snmp subagent" )
#endif
;
replication_options.add_options()
@ -822,6 +831,12 @@ int main(int argc, char* argv[], char *envp[] )
setRecCacheSize(x);
}
#ifdef _HAVESNMP
if ( params.count( "snmp-subagent" ) ){
snmpAgent.enable();
}
#endif
if ( params.count( "mms-token" ) ){
mms.setToken( params["mms-token"].as<string>() );
}

103
db/snmp.cpp Normal file
View File

@ -0,0 +1,103 @@
// snmp.cpp
#include "../stdafx.h"
#include "../util/background.h"
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include <signal.h>
#include "snmp.h"
namespace mongo {
static oid myoid[] =
{ 1, 3, 6, 1, 4, 1, 8072, 2, 4, 1, 1, 2, 0};
static int myvalue = 18;
SNMPAgent::SNMPAgent(){
_enabled = 0;
_subagent = 1;
_snmpIterations = 0;
_numThings = 0;
_agentName = "mongod";
}
void SNMPAgent::enable(){
_enabled = 1;
}
void SNMPAgent::makeMaster(){
_subagent = false;
}
void SNMPAgent::run(){
if ( ! _enabled ){
log(1) << "SNMPAgent not enabled" << endl;
return;
}
snmp_enable_stderrlog();
if ( _subagent ){
if ( netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_ROLE, 1) != SNMPERR_SUCCESS ){
log() << "SNMPAgent faild setting subagent" << endl;
return;
}
}
//SOCK_STARTUP;
init_agent( _agentName.c_str() );
_init();
log(1) << "SNMPAgent num things: " << _numThings << endl;
init_snmp( _agentName.c_str() );
if ( ! _subagent )
init_master_agent();
log() << "SNMPAgent running" << endl;
while( ! inShutdown() ){
_snmpIterations++;
agent_check_and_process(1);
}
log() << "SNMPAgent shutting down" << endl;
snmp_shutdown( _agentName.c_str() );
SOCK_CLEANUP;
}
void SNMPAgent::_checkRegister( int x ){
if ( x == MIB_REGISTERED_OK ){
_numThings++;
return;
}
if ( x == MIB_REGISTRATION_FAILED ){
log() << "SNMPAgent MIB_REGISTRATION_FAILED!" << endl;
}
else if ( x == MIB_DUPLICATE_REGISTRATION ){
log() << "SNMPAgent MIB_DUPLICATE_REGISTRATION!" << endl;
}
else {
log() << "SNMPAgent unknown registration failure" << endl;
}
}
void SNMPAgent::_init(){
_checkRegister( netsnmp_register_int_instance( "asdasd" ,
myoid , OID_LENGTH( myoid ) ,
&myvalue , NULL ) );
}
SNMPAgent snmpAgent;
}

31
db/snmp.h Normal file
View File

@ -0,0 +1,31 @@
// snmp.h
#include "../stdafx.h"
#include "../util/background.h"
namespace mongo {
class SNMPAgent : public BackgroundJob {
public:
SNMPAgent();
void enable();
void makeMaster();
void run();
private:
void _init();
void _checkRegister( int x );
string _agentName;
bool _enabled;
bool _subagent;
int _numThings;
int _snmpIterations;
};
extern SNMPAgent snmpAgent;
}