| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- #pragma once
- #include "TSysThread.h"
- #include "TSysThreadPool.h"
- #define HAVE_SSIZE_T
- extern "C" {
- #include "net-snmp/net-snmp-config.h"
- #include "net-snmp/net-snmp-includes.h"
- #include "net-snmp/agent/net-snmp-agent-includes.h"
- #include "net-snmp/library/fd_event_manager.h"
- #include "net-snmp/agent/netsnmp_close_fds.h"
- #include "net-snmp/snmplib/snmp_syslog.h"
- #include "net-snmp/agent/agent_global_vars.h"
- #include "net-snmp/agent/mibgroup/snmpv3/snmpEngine.h"
- #include "net-snmp/agent/mibgroup/snmpv3/usmUser.h"
- #include "net-snmp/agent/mibgroup/agent/nsVacmAccessTable.h"
- #include "net-snmp/agent/mibgroup/agentx/subagent.h"
-
-
- #include "net-snmp/agent/mibgroup/notification-log-mib/notification_log.h"
- #include "net-snmp/agent/mibgroup/tlstm-mib/snmpTlstmCertToTSNTable/snmpTlstmCertToTSNTable.h"
- #include "net-snmp/agent/mibgroup/mibII/vacm_conf.h"
- }
- #include "snmptrapd_handlers.h"
- #include "snmptrapd_log.h"
- #include "snmptrapd_auth.h"
- #include "snmptrapd_sql.h"
- /*
- * Include winservice.h to support Windows Service
- */
- #ifdef WIN32
- #include <windows.h>
- #include <tchar.h>
- extern "C" {
- #include "net-snmp/library/winservice.h"
- }
- #define WIN32SERVICE
- #endif
- extern "C" {
- #include "net-snmp/net-snmp-features.h"
- }
- #ifndef BSD4_3
- #define BSD4_2
- #endif
- #define SNMPTRAPD_RUNNING 1
- #define SNMPTRAPD_STOPPED 0
- #define PRINT_V23_NOTIFICATION_FORMAT "%.4y-%.2m-%.2l %.2h:%.2j:%.2k %B [%b]:\n%v\n"
- typedef struct tagDEVICEINFO_{
- std::string srcip;
- std::string port_index;
- }DEVICEINFO;
- class CSnmpClass : public TSysThreadImpl {
- public:
- CSnmpClass();
- ~CSnmpClass();
- int Init(std::string addr);
- static void* m_pInstance;
- TSysThreadPool *m_pOolInvoker;
- void Action();
- std::string m_sDeviceIp;
- int m_nPowerFlag; // 0/正常 1/报警
- int m_nErpsFlag;// 0/正常 1/报警
- int m_nPhyFlag;// 0/正常 1/报警
- int m_nBoardFlag;// 0/正常 1/报警
- std::vector <DEVICEINFO*> m_pWhite_list;
- int m_nAlarmStatus;
- int m_nMtime;
- int m_needTime;
- std::mutex m_Alarm;
- std::string m_sCommunity;
- std::string m_receive_bind_ip;
- std::string m_send_bind_ip;
- char m_bindip[100];
- std::vector<std::string> m_identity;
- std::vector<std::string> m_dst_ip;
- std::string m_systemType;
- private:
- static char *m_pDdefault_port; /* Default default port */
- static char *m_pDefault_port;
- char *m_pTrap1_fmt_str_remember;
- static int m_nDofork;
- int m_nTrapd_status;
- /* m_pApp_name_long used for SCM, registry etc */
- LPCSTR m_pApp_name_long; /* Application Name */
- const char *m_pApp_name;
- void GetIdentity(std::string data);
- bool LoadDeviceInfo();
- bool CheckPower(std::string buf, std::string comunnity);
- bool CheckResetPower(std::string buf, std::string comunnity);
- bool CheckNetwork(std::string buf, std::string comunnity);
- bool CheckPort_index(std::string src,std::string port_index);
- bool FindNetAlarm(std::string buf, std::string comunnity, std::string moduleIdentity);
- void StopSnmpTrapd(void);
- static RETSIGTYPE TermHandler(int sig);
- static int PreParse(netsnmp_session * session, netsnmp_transport *transport, void *transport_data, int transport_data_length);
- netsnmp_session * SnmptrapdAddSession(netsnmp_transport *t);
- void SnmptrapdCloseSessions(netsnmp_session * sess_list);
- static void ParseTrapdAddress(const char *token, char *cptr);
- static void FreeTrapdAddress(void);
- static void ParseConfigDoNotLogTraps(const char *token, char *cptr);
- static void ParseConfigDoNotFork(const char *token, char *cptr);
- static void ParseConfigIgnoreAuthFailure(const char *token, char *cptr);
- static void ParseConfigOutputOption(const char *token, char *cptr);
- static void ParseConfigAddForwarderInfo(const char *token, char *cptr);
- void SnmptrapdMainLoop(void);
- int SnmpTrapdMain(int argc, char * argv[]);
- void ReadProcess(std::string buf, std::string comunnity);
- void InitNetsnmpTrapdAuth(void);
- static int PrintHandler(netsnmp_pdu* pdu, netsnmp_transport* transport, netsnmp_trapd_handler * handler);
- static int RecvHandler(netsnmp_pdu* pdu, netsnmp_transport *transport, netsnmp_trapd_handler * handler);
- void ParseBuffer(std::string buf, std::string comunnity);
- void MoxaParseBuffer(std::string buf, std::string comunnity);
- void H3cParseBuffer(std::string buf, std::string comunnity);
- int ParsePtype(std::string buf, std::string upAnddown);
- int ParseEtype(std::string buf, std::string upAnddown);
- int ParseBtype(std::string buf);
- std::string FindString(std::string a, std::string b);
- bool FindIntegerOrSend(std::string src, std::string comunnity, std::string moduleIdentity, std::string power);
- void SendString(int status, std::string comunnity, std::string buf, std::string moduleIdentity, std::string power);
- void SendStringH3c(int status, std::string comunnity, std::string buf);
- };
|