From: Maxim Mamontov Date: Wed, 31 Aug 2011 10:04:17 +0000 (+0300) Subject: Rules counter added to the SMUX plugin X-Git-Tag: 2.408-alpha~14 X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/e19060886ea59cbcb0c97e1712a954f729ef47b3 Rules counter added to the SMUX plugin --- diff --git a/projects/stargazer/plugins/other/smux/sensors.h b/projects/stargazer/plugins/other/smux/sensors.h index 55780987..7c11751e 100644 --- a/projects/stargazer/plugins/other/smux/sensors.h +++ b/projects/stargazer/plugins/other/smux/sensors.h @@ -8,6 +8,7 @@ #include "stg/admins.h" #include "stg/services.h" #include "stg/corporations.h" +#include "stg/traffcounter.h" #include "stg/user_property.h" #include "stg/ObjectSyntax.h" @@ -241,6 +242,26 @@ class TotalCorporationsSensor : public Sensor { const CORPORATIONS & corporations; }; +class TotalRulesSensor : public Sensor { + public: + TotalRulesSensor(const TRAFFCOUNTER & t) : traffcounter(t) {} + virtual ~TotalRulesSensor() {} + + bool GetValue(ObjectSyntax_t * objectSyntax) const + { + ValueToOS(traffcounter.RulesCount(), objectSyntax); + return true; + } + +#ifdef DEBUG + std::string ToString() const + { std::string res; x2str(traffcounter.RulesCount(), res); return res; } +#endif + + private: + const TRAFFCOUNTER & traffcounter; +}; + template class ConstSensor : public Sensor { public: diff --git a/projects/stargazer/plugins/other/smux/smux.cpp b/projects/stargazer/plugins/other/smux/smux.cpp index 1300452f..d3f5bbdb 100644 --- a/projects/stargazer/plugins/other/smux/smux.cpp +++ b/projects/stargazer/plugins/other/smux/smux.cpp @@ -16,11 +16,12 @@ #include "stg/common.h" #include "stg/plugin_creator.h" -#include "stg/users.h" +/*#include "stg/users.h" #include "stg/tariffs.h" #include "stg/admins.h" #include "stg/services.h" #include "stg/corporations.h" +#include "stg/traffcounter.h"*/ #include "smux.h" #include "utils.h" @@ -98,6 +99,7 @@ SMUX::SMUX() admins(NULL), services(NULL), corporations(NULL), + traffcounter(NULL), running(false), stopped(true), sock(-1) @@ -137,11 +139,12 @@ return smuxSettings.ParseSettings(settings); int SMUX::Start() { -assert(users != NULL && "users not NULL"); -assert(tariffs != NULL && "tariffs not NULL"); -assert(admins != NULL && "admins not NULL"); -assert(services != NULL && "services not NULL"); -assert(corporations != NULL && "corporations not NULL"); +assert(users != NULL && "users must not be NULL"); +assert(tariffs != NULL && "tariffs must not be NULL"); +assert(admins != NULL && "admins must not be NULL"); +assert(services != NULL && "services must not be NULL"); +assert(corporations != NULL && "corporations must not be NULL"); +assert(traffcounter != NULL && "traffcounter must not be NULL"); if (PrepareNet()) return -1; @@ -166,6 +169,8 @@ sensors[OID(".1.3.6.1.4.1.38313.1.3.1")] = new TotalAdminsSensor(*admins); sensors[OID(".1.3.6.1.4.1.38313.1.4.1")] = new TotalServicesSensor(*services); // Corporations sensors[OID(".1.3.6.1.4.1.38313.1.5.1")] = new TotalCorporationsSensor(*corporations); +// Traffcounter +sensors[OID(".1.3.6.1.4.1.38313.1.6.1")] = new TotalRulesSensor(*traffcounter); // Table data tables[".1.3.6.1.4.1.38313.1.1.6"] = new TariffUsersTable(".1.3.6.1.4.1.38313.1.1.6", *users); diff --git a/projects/stargazer/plugins/other/smux/smux.h b/projects/stargazer/plugins/other/smux/smux.h index 5230a85c..03d3d3b6 100644 --- a/projects/stargazer/plugins/other/smux/smux.h +++ b/projects/stargazer/plugins/other/smux/smux.h @@ -26,6 +26,7 @@ class USERS; class TARIFFS; class SERVICES; class CORPORATIONS; +class TRAFFCOUNTER; typedef bool (SMUX::*SMUXPacketHandler)(const SMUX_PDUs_t * pdus); typedef bool (SMUX::*PDUsHandler)(const PDUs_t * pdus); @@ -60,6 +61,7 @@ public: void SetTariffs(TARIFFS * t) { tariffs = t; } void SetAdmins(ADMINS * a) { admins = a; } void SetServices(SERVICES * s) { services = s; } + void SetTraffcounter(TRAFFCOUNTER * tc) { traffcounter = tc; } void SetCorporations(CORPORATIONS * c) { corporations = c; } void SetSettings(const MODULE_SETTINGS & s) { settings = s; } int ParseSettings(); @@ -97,6 +99,7 @@ private: ADMINS * admins; SERVICES * services; CORPORATIONS * corporations; + TRAFFCOUNTER * traffcounter; mutable std::string errorStr; SMUX_SETTINGS smuxSettings;