From: Maxim Mamontov <faust.madf@gmail.com>
Date: Mon, 26 Dec 2011 09:04:07 +0000 (+0200)
Subject: New sensor added: ActiveUsers
X-Git-Tag: 2.408~30
X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/5fdfdde84e79b2430924e8241bb3ef4579214f2f?ds=inline

New sensor added: ActiveUsers
---

diff --git a/projects/stargazer/plugins/other/smux/STG-MIB.mib b/projects/stargazer/plugins/other/smux/STG-MIB.mib
index 8eaffb3d..bccf5a28 100644
--- a/projects/stargazer/plugins/other/smux/STG-MIB.mib
+++ b/projects/stargazer/plugins/other/smux/STG-MIB.mib
@@ -126,6 +126,15 @@ tariffChangeUsers OBJECT-TYPE
     DEFVAL { 0 }
     ::= { users 11 }
 
+activeUsers OBJECT-TYPE
+    SYNTAX      Integer32
+    MAX-ACCESS  read-only
+    STATUS      current
+    DESCRIPTION
+        "The number of online users with traffic during session"
+    DEFVAL {0}
+    ::= { users 12 }
+
 totalTariffs OBJECT-TYPE
     SYNTAX      Integer32
     MAX-ACCESS  read-only
diff --git a/projects/stargazer/plugins/other/smux/sensors.cpp b/projects/stargazer/plugins/other/smux/sensors.cpp
index 9cfdadd0..f52a413b 100644
--- a/projects/stargazer/plugins/other/smux/sensors.cpp
+++ b/projects/stargazer/plugins/other/smux/sensors.cpp
@@ -46,3 +46,16 @@ x2str(count, res);
 return res;
 }
 #endif
+
+bool ActiveUsersSensor::UserPredicate(USER_PTR userPtr) const
+{
+if (!userPtr->GetConnected())
+    return false;
+for (size_t i = 0; i < DIR_NUM; ++i)
+    {
+    if (userPtr->GetSessionUpload()[i] > 0 ||
+        userPtr->GetSessionDownload()[i] > 0)
+        return true;
+    }
+return false;
+}
diff --git a/projects/stargazer/plugins/other/smux/sensors.h b/projects/stargazer/plugins/other/smux/sensors.h
index 3337323e..3787611f 100644
--- a/projects/stargazer/plugins/other/smux/sensors.h
+++ b/projects/stargazer/plugins/other/smux/sensors.h
@@ -163,6 +163,15 @@ class TariffChangeUsersSensor : public UsersSensor {
         { return !userPtr->GetProperty().nextTariff.ConstData().empty(); }
 };
 
+class ActiveUsersSensor : public UsersSensor {
+    public:
+        ActiveUsersSensor(USERS & u) : UsersSensor(u) {}
+        virtual ~ActiveUsersSensor() {}
+
+    private:
+        bool UserPredicate(USER_PTR userPtr) const;
+};
+
 class TotalTariffsSensor : public Sensor {
     public:
         TotalTariffsSensor(const TARIFFS & t) : tariffs(t) {}
diff --git a/projects/stargazer/plugins/other/smux/smux.cpp b/projects/stargazer/plugins/other/smux/smux.cpp
index fcc0a9c2..7372948a 100644
--- a/projects/stargazer/plugins/other/smux/smux.cpp
+++ b/projects/stargazer/plugins/other/smux/smux.cpp
@@ -170,6 +170,7 @@ sensors[OID(".1.3.6.1.4.1.38313.1.1.8")] = new PassiveUsersSensor(*users);
 sensors[OID(".1.3.6.1.4.1.38313.1.1.9")] = new CreditUsersSensor(*users);
 sensors[OID(".1.3.6.1.4.1.38313.1.1.10")] = new FreeMbUsersSensor(*users);
 sensors[OID(".1.3.6.1.4.1.38313.1.1.11")] = new TariffChangeUsersSensor(*users);
+sensors[OID(".1.3.6.1.4.1.38313.1.1.12")] = new ActiveUsersSensor(*users);
 // Tariffs
 sensors[OID(".1.3.6.1.4.1.38313.1.2.1")] = new TotalTariffsSensor(*tariffs);
 // Admins