]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/other/snmp/sensors.cpp
Full month stats patches added (derived from GTS version)
[stg.git] / projects / stargazer / plugins / other / snmp / sensors.cpp
1 #include "asn1/INTEGER.h"
2
3 #include "stg/user.h"
4 #include "stg/user_property.h"
5
6 #include "sensors.h"
7
8 void Int2OS(ObjectSyntax_t * dst, long src)
9 {
10 dst->present = ObjectSyntax_PR_simple;
11 SimpleSyntax_t * simpleSyntax = &dst->choice.simple;
12 simpleSyntax->present = SimpleSyntax_PR_number;
13 asn_long2INTEGER(&simpleSyntax->choice.number, src);
14 }
15
16 bool ConnectedUsersSensor::GetValue(ObjectSyntax_t * objectSyntax)
17 {
18 int handle = users.OpenSearch();
19 if (!handle)
20     return false;
21
22 USER_PTR user;
23 size_t count = 0;
24 while (!users.SearchNext(handle, &user))
25     {
26     if (user->GetConnected())
27         ++count;
28     }
29
30 users.CloseSearch(handle);
31
32 Int2OS(objectSyntax, count);
33 return true;
34 }
35
36 bool AuthorizedUsersSensor::GetValue(ObjectSyntax_t * objectSyntax)
37 {
38 int handle = users.OpenSearch();
39 if (!handle)
40     return false;
41
42 USER_PTR user;
43 size_t count = 0;
44 while (!users.SearchNext(handle, &user))
45     {
46     if (user->GetAuthorized())
47         ++count;
48     }
49
50 users.CloseSearch(handle);
51
52 Int2OS(objectSyntax, count);
53 return true;
54 }
55
56 bool AlwaysOnlineUsersSensor::GetValue(ObjectSyntax_t * objectSyntax)
57 {
58 int handle = users.OpenSearch();
59 if (!handle)
60     return false;
61
62 USER_PTR user;
63 size_t count = 0;
64 while (!users.SearchNext(handle, &user))
65     {
66     if (user->GetProperty().alwaysOnline)
67         ++count;
68     }
69
70 users.CloseSearch(handle);
71
72 Int2OS(objectSyntax, count);
73 return true;
74 }
75
76 bool NoCashUsersSensor::GetValue(ObjectSyntax_t * objectSyntax)
77 {
78 int handle = users.OpenSearch();
79 if (!handle)
80     return false;
81
82 USER_PTR user;
83 size_t count = 0;
84 while (!users.SearchNext(handle, &user))
85     {
86     if (user->GetProperty().cash < 0)
87         ++count;
88     }
89
90 users.CloseSearch(handle);
91
92 Int2OS(objectSyntax, count);
93 return true;
94 }
95
96 bool DisabledDetailStatsUsersSensor::GetValue(ObjectSyntax_t * objectSyntax)
97 {
98 int handle = users.OpenSearch();
99 if (!handle)
100     return false;
101
102 USER_PTR user;
103 size_t count = 0;
104 while (!users.SearchNext(handle, &user))
105     {
106     if (user->GetProperty().disabledDetailStat)
107         ++count;
108     }
109
110 users.CloseSearch(handle);
111
112 Int2OS(objectSyntax, count);
113 return true;
114 }
115
116 bool DisabledUsersSensor::GetValue(ObjectSyntax_t * objectSyntax)
117 {
118 int handle = users.OpenSearch();
119 if (!handle)
120     return false;
121
122 USER_PTR user;
123 size_t count = 0;
124 while (!users.SearchNext(handle, &user))
125     {
126     if (user->GetProperty().disabled)
127         ++count;
128     }
129
130 users.CloseSearch(handle);
131
132 Int2OS(objectSyntax, count);
133 return true;
134 }
135
136 bool PassiveUsersSensor::GetValue(ObjectSyntax_t * objectSyntax)
137 {
138 int handle = users.OpenSearch();
139 if (!handle)
140     return false;
141
142 USER_PTR user;
143 size_t count = 0;
144 while (!users.SearchNext(handle, &user))
145     {
146     if (user->GetProperty().passive)
147         ++count;
148     }
149
150 users.CloseSearch(handle);
151
152 Int2OS(objectSyntax, count);
153 return true;
154 }
155
156 bool CreditUsersSensor::GetValue(ObjectSyntax_t * objectSyntax)
157 {
158 int handle = users.OpenSearch();
159 if (!handle)
160     return false;
161
162 USER_PTR user;
163 size_t count = 0;
164 while (!users.SearchNext(handle, &user))
165     {
166     if (user->GetProperty().credit > 0)
167         ++count;
168     }
169
170 users.CloseSearch(handle);
171
172 Int2OS(objectSyntax, count);
173 return true;
174 }
175
176 bool FreeMbUsersSensor::GetValue(ObjectSyntax_t * objectSyntax)
177 {
178 int handle = users.OpenSearch();
179 if (!handle)
180     return false;
181
182 USER_PTR user;
183 size_t count = 0;
184 while (!users.SearchNext(handle, &user))
185     {
186     if (user->GetProperty().freeMb > 0)
187         ++count;
188     }
189
190 users.CloseSearch(handle);
191
192 Int2OS(objectSyntax, count);
193 return true;
194 }