]> git.stg.codes - stg.git/commitdiff
Data sensors added
authorMaxim Mamontov <faust.madf@gmail.com>
Fri, 10 Jun 2011 07:52:43 +0000 (10:52 +0300)
committerMaxim Mamontov <faust.madf@gmail.com>
Fri, 10 Jun 2011 07:52:43 +0000 (10:52 +0300)
projects/stargazer/plugins/other/snmp/Makefile
projects/stargazer/plugins/other/snmp/sensors.cpp [new file with mode: 0644]
projects/stargazer/plugins/other/snmp/sensors.h [new file with mode: 0644]

index 047c29ec775188b6bd1bcab533d2c8edb69587df..d43398243abea153194512e6c4d9b9184c7e5cf3 100644 (file)
@@ -9,6 +9,7 @@ LIBS += $(LIB_THREAD)
 PROG = mod_snmp_agent.so
 
 SRCS =  snmp.cpp \
+       sensors.cpp \
        asn1/DisplayString.c    \
        asn1/PhysAddress.c      \
        asn1/IfEntry.c  \
diff --git a/projects/stargazer/plugins/other/snmp/sensors.cpp b/projects/stargazer/plugins/other/snmp/sensors.cpp
new file mode 100644 (file)
index 0000000..a9f8efc
--- /dev/null
@@ -0,0 +1,194 @@
+#include "asn1/INTEGER.h"
+
+#include "stg/user.h"
+#include "stg/user_property.h"
+
+#include "sensors.h"
+
+void Int2OS(ObjectSyntax_t * dst, long src)
+{
+dst->present = ObjectSyntax_PR_simple;
+SimpleSyntax_t * simpleSyntax = &dst->choice.simple;
+simpleSyntax->present = SimpleSyntax_PR_number;
+asn_long2INTEGER(&simpleSyntax->choice.number, src);
+}
+
+bool ConnectedUsersSensor::GetValue(ObjectSyntax_t * objectSyntax)
+{
+int handle = users.OpenSearch();
+if (!handle)
+    return false;
+
+USER_PTR user;
+size_t count = 0;
+while (!users.SearchNext(handle, &user))
+    {
+    if (user->GetConnected())
+        ++count;
+    }
+
+users.CloseSearch(handle);
+
+Int2OS(objectSyntax, count);
+return true;
+}
+
+bool AuthorizedUsersSensor::GetValue(ObjectSyntax_t * objectSyntax)
+{
+int handle = users.OpenSearch();
+if (!handle)
+    return false;
+
+USER_PTR user;
+size_t count = 0;
+while (!users.SearchNext(handle, &user))
+    {
+    if (user->GetAuthorized())
+        ++count;
+    }
+
+users.CloseSearch(handle);
+
+Int2OS(objectSyntax, count);
+return true;
+}
+
+bool AlwaysOnlineUsersSensor::GetValue(ObjectSyntax_t * objectSyntax)
+{
+int handle = users.OpenSearch();
+if (!handle)
+    return false;
+
+USER_PTR user;
+size_t count = 0;
+while (!users.SearchNext(handle, &user))
+    {
+    if (user->GetProperty().alwaysOnline)
+        ++count;
+    }
+
+users.CloseSearch(handle);
+
+Int2OS(objectSyntax, count);
+return true;
+}
+
+bool NoCashUsersSensor::GetValue(ObjectSyntax_t * objectSyntax)
+{
+int handle = users.OpenSearch();
+if (!handle)
+    return false;
+
+USER_PTR user;
+size_t count = 0;
+while (!users.SearchNext(handle, &user))
+    {
+    if (user->GetProperty().cash < 0)
+        ++count;
+    }
+
+users.CloseSearch(handle);
+
+Int2OS(objectSyntax, count);
+return true;
+}
+
+bool DisabledDetailStatsUsersSensor::GetValue(ObjectSyntax_t * objectSyntax)
+{
+int handle = users.OpenSearch();
+if (!handle)
+    return false;
+
+USER_PTR user;
+size_t count = 0;
+while (!users.SearchNext(handle, &user))
+    {
+    if (user->GetProperty().disabledDetailStat)
+        ++count;
+    }
+
+users.CloseSearch(handle);
+
+Int2OS(objectSyntax, count);
+return true;
+}
+
+bool DisabledUsersSensor::GetValue(ObjectSyntax_t * objectSyntax)
+{
+int handle = users.OpenSearch();
+if (!handle)
+    return false;
+
+USER_PTR user;
+size_t count = 0;
+while (!users.SearchNext(handle, &user))
+    {
+    if (user->GetProperty().disabled)
+        ++count;
+    }
+
+users.CloseSearch(handle);
+
+Int2OS(objectSyntax, count);
+return true;
+}
+
+bool PassiveUsersSensor::GetValue(ObjectSyntax_t * objectSyntax)
+{
+int handle = users.OpenSearch();
+if (!handle)
+    return false;
+
+USER_PTR user;
+size_t count = 0;
+while (!users.SearchNext(handle, &user))
+    {
+    if (user->GetProperty().passive)
+        ++count;
+    }
+
+users.CloseSearch(handle);
+
+Int2OS(objectSyntax, count);
+return true;
+}
+
+bool CreditUsersSensor::GetValue(ObjectSyntax_t * objectSyntax)
+{
+int handle = users.OpenSearch();
+if (!handle)
+    return false;
+
+USER_PTR user;
+size_t count = 0;
+while (!users.SearchNext(handle, &user))
+    {
+    if (user->GetProperty().credit > 0)
+        ++count;
+    }
+
+users.CloseSearch(handle);
+
+Int2OS(objectSyntax, count);
+return true;
+}
+
+bool FreeMbUsersSensor::GetValue(ObjectSyntax_t * objectSyntax)
+{
+int handle = users.OpenSearch();
+if (!handle)
+    return false;
+
+USER_PTR user;
+size_t count = 0;
+while (!users.SearchNext(handle, &user))
+    {
+    if (user->GetProperty().freeMb > 0)
+        ++count;
+    }
+
+users.CloseSearch(handle);
+
+Int2OS(objectSyntax, count);
+return true;
+}
diff --git a/projects/stargazer/plugins/other/snmp/sensors.h b/projects/stargazer/plugins/other/snmp/sensors.h
new file mode 100644 (file)
index 0000000..49a0830
--- /dev/null
@@ -0,0 +1,172 @@
+#ifndef __SENSORS_H__
+#define __SENSORS_H__
+
+#include <string>
+#include <map>
+
+#include "stg/users.h"
+#include "stg/tariffs.h"
+
+#include "asn1/ObjectSyntax.h"
+
+class Sensor {
+    public:
+        virtual bool GetValue(ObjectSyntax_t * objectSyntax) = 0;
+};
+
+typedef std::map<std::string, Sensor *> Sensors;
+
+void Int2OS(ObjectSyntax_t * dst, long src);
+
+class TotalUsersSensor : public Sensor {
+    public:
+        TotalUsersSensor(const USERS & u)
+            : users(u)
+        {}
+        virtual ~TotalUsersSensor() {}
+
+        bool GetValue(ObjectSyntax_t * objectSyntax)
+        {
+        Int2OS(objectSyntax, users.GetUserNum());
+        return true;
+        }
+
+    private:
+        const USERS & users;
+};
+
+class ConnectedUsersSensor : public Sensor {
+    public:
+        ConnectedUsersSensor(USERS & u)
+            : users(u)
+        {}
+        virtual ~ConnectedUsersSensor() {}
+
+        bool GetValue(ObjectSyntax_t * objectSyntax);
+
+    private:
+        USERS & users;
+};
+
+class AuthorizedUsersSensor : public Sensor {
+    public:
+        AuthorizedUsersSensor(USERS & u)
+            : users(u)
+        {}
+        virtual ~AuthorizedUsersSensor() {}
+
+        bool GetValue(ObjectSyntax_t * objectSyntax);
+
+    private:
+        USERS & users;
+};
+
+class AlwaysOnlineUsersSensor : public Sensor {
+    public:
+        AlwaysOnlineUsersSensor(USERS & u)
+            : users(u)
+        {}
+        virtual ~AlwaysOnlineUsersSensor() {}
+
+        bool GetValue(ObjectSyntax_t * objectSyntax);
+
+    private:
+        USERS & users;
+};
+
+class NoCashUsersSensor : public Sensor {
+    public:
+        NoCashUsersSensor(USERS & u)
+            : users(u)
+        {}
+        virtual ~NoCashUsersSensor() {}
+
+        bool GetValue(ObjectSyntax_t * objectSyntax);
+
+    private:
+        USERS & users;
+};
+
+class DisabledDetailStatsUsersSensor : public Sensor {
+    public:
+        DisabledDetailStatsUsersSensor(USERS & u)
+            : users(u)
+        {}
+        virtual ~DisabledDetailStatsUsersSensor() {}
+
+        bool GetValue(ObjectSyntax_t * objectSyntax);
+
+    private:
+        USERS & users;
+};
+
+class DisabledUsersSensor : public Sensor {
+    public:
+        DisabledUsersSensor(USERS & u)
+            : users(u)
+        {}
+        virtual ~DisabledUsersSensor() {}
+
+        bool GetValue(ObjectSyntax_t * objectSyntax);
+
+    private:
+        USERS & users;
+};
+
+class PassiveUsersSensor : public Sensor {
+    public:
+        PassiveUsersSensor(USERS & u)
+            : users(u)
+        {}
+        virtual ~PassiveUsersSensor() {}
+
+        bool GetValue(ObjectSyntax_t * objectSyntax);
+
+    private:
+        USERS & users;
+};
+
+class CreditUsersSensor : public Sensor {
+    public:
+        CreditUsersSensor(USERS & u)
+            : users(u)
+        {}
+        virtual ~CreditUsersSensor() {}
+
+        bool GetValue(ObjectSyntax_t * objectSyntax);
+
+    private:
+        USERS & users;
+};
+
+class FreeMbUsersSensor : public Sensor {
+    public:
+        FreeMbUsersSensor(USERS & u)
+            : users(u)
+        {}
+        virtual ~FreeMbUsersSensor() {}
+
+        bool GetValue(ObjectSyntax_t * objectSyntax);
+
+    private:
+        USERS & users;
+};
+
+class TotalTariffsSensor : public Sensor {
+    public:
+        TotalTariffsSensor(const TARIFFS & t)
+            : tariffs(t)
+        {}
+        virtual ~TotalTariffsSensor() {}
+
+        bool GetValue(ObjectSyntax_t * objectSyntax)
+        {
+        Int2OS(objectSyntax, tariffs.GetTariffsNum());
+        return true;
+        }
+
+    private:
+        const TARIFFS & tariffs;
+};
+
+#endif