@@ -29,6 +29,7 @@ const servicestatusAPI = "/objects/servicestatus"
29
29
const systeminfoAPI = "/system/info"
30
30
const systemstatusAPI = "/system/status"
31
31
const systemstatusDetailAPI = "/system/statusdetail"
32
+ const systemuserAPI = "/system/user"
32
33
33
34
type systemStatus struct {
34
35
// https://stackoverflow.com/questions/21151765/cannot-unmarshal-string-into-go-value-of-type-int64
@@ -107,6 +108,15 @@ type serviceStatus struct {
107
108
} `json:"servicestatus"`
108
109
}
109
110
111
+ type userStatus struct {
112
+ // yes, this field is named records even though every other endpoint is `recordcount`...
113
+ Recordcount int64 `json:"records"`
114
+ Userstatus []struct {
115
+ Admin int64 `json:"admin,string"`
116
+ Enabled int64 `json:"enabled,string"`
117
+ } `json:"users"`
118
+ }
119
+
110
120
func ReadConfig (configPath string ) Config {
111
121
112
122
var conf Config
@@ -153,6 +163,11 @@ var (
153
163
// technically there is no such thing as a check_type of passive for these metrics
154
164
hostchecksPerformance = prometheus .NewDesc (prometheus .BuildFQName (namespace , "" , "host_checks_performance_seconds" ), "Host checks performance" , []string {"check_type" , "performance_type" , "operator" }, nil )
155
165
servicechecksPerformance = prometheus .NewDesc (prometheus .BuildFQName (namespace , "" , "service_checks_performance_seconds" ), "Service checks performance" , []string {"check_type" , "performance_type" , "operator" }, nil )
166
+
167
+ // Users
168
+ usersTotal = prometheus .NewDesc (prometheus .BuildFQName (namespace , "" , "users_total" ), "Amount of users present on the system" , nil , nil )
169
+ usersPrivileges = prometheus .NewDesc (prometheus .BuildFQName (namespace , "" , "users_privileges_total" ), "Amount of admin or regular users" , []string {"privileges" }, nil )
170
+ usersStatus = prometheus .NewDesc (prometheus .BuildFQName (namespace , "" , "users_status_total" ), "Amount of disabled or enabled users" , []string {"status" }, nil )
156
171
)
157
172
158
173
type Exporter struct {
@@ -193,6 +208,10 @@ func (e *Exporter) Describe(ch chan<- *prometheus.Desc) {
193
208
ch <- servicechecks
194
209
ch <- hostchecksPerformance
195
210
ch <- servicechecksPerformance
211
+ // Users
212
+ ch <- usersTotal
213
+ ch <- usersPrivileges
214
+ ch <- usersStatus
196
215
}
197
216
198
217
func (e * Exporter ) TestNagiosConnectivity (sslVerify bool , nagiosAPITimeout time.Duration ) float64 {
@@ -392,7 +411,7 @@ func (e *Exporter) QueryAPIsAndUpdateMetrics(ch chan<- prometheus.Metric, sslVer
392
411
servicesTotal , prometheus .GaugeValue , float64 (serviceStatusObject .Recordcount ),
393
412
)
394
413
395
- var servicesCount , servicessCheckedCount , servicesScheduledCount , servicesActiveCheckCount ,
414
+ var servicesCount , servicesCheckedCount , servicesScheduledCount , servicesActiveCheckCount ,
396
415
servicesPassiveCheckCount , servicesOkCount , servicesWarnCount , servicesCriticalCount ,
397
416
servicesUnknownCount , servicesFlapCount , servicesDowntimeCount , servicesProblemsAcknowledgedCount int
398
417
@@ -401,7 +420,7 @@ func (e *Exporter) QueryAPIsAndUpdateMetrics(ch chan<- prometheus.Metric, sslVer
401
420
servicesCount ++
402
421
403
422
if v .HasBeenChecked == 0 {
404
- servicessCheckedCount ++
423
+ servicesCheckedCount ++
405
424
}
406
425
407
426
if v .ShouldBeScheduled == 0 {
@@ -581,6 +600,57 @@ func (e *Exporter) QueryAPIsAndUpdateMetrics(ch chan<- prometheus.Metric, sslVer
581
600
servicechecksPerformance , prometheus .GaugeValue , float64 (systemStatusDetailObject .Nagioscore .Activeservicecheckperf .MinExecutionTime ), "active" , "execution" , "max" ,
582
601
)
583
602
603
+ // user information
604
+ // we also need to tack on the optional parameter of `advanced` to get privilege information
605
+ systemUserURL := e .nagiosEndpoint + systemuserAPI + "?apikey=" + e .nagiosAPIKey + "&advanced=1"
606
+
607
+ body = QueryAPIs (systemUserURL , sslVerify , nagiosAPITimeout )
608
+ log .Debug ("Queried API: " , systemuserAPI )
609
+
610
+ userStatusObject := userStatus {}
611
+
612
+ jsonErr = json .Unmarshal (body , & userStatusObject )
613
+ if jsonErr != nil {
614
+ log .Fatal (jsonErr )
615
+ }
616
+
617
+ var usersAdminCount , usersRegularCount , usersEnabledCount , usersDisabledCount int
618
+
619
+ ch <- prometheus .MustNewConstMetric (
620
+ usersTotal , prometheus .GaugeValue , float64 (userStatusObject .Recordcount ),
621
+ )
622
+
623
+ for _ , v := range userStatusObject .Userstatus {
624
+
625
+ if v .Admin == 1 {
626
+ usersAdminCount ++
627
+ } else {
628
+ usersRegularCount ++
629
+ }
630
+
631
+ if v .Enabled == 1 {
632
+ usersEnabledCount ++
633
+ } else {
634
+ usersDisabledCount ++
635
+ }
636
+ }
637
+
638
+ ch <- prometheus .MustNewConstMetric (
639
+ usersStatus , prometheus .GaugeValue , float64 (usersEnabledCount ), "enabled" ,
640
+ )
641
+
642
+ ch <- prometheus .MustNewConstMetric (
643
+ usersStatus , prometheus .GaugeValue , float64 (usersDisabledCount ), "disabled" ,
644
+ )
645
+
646
+ ch <- prometheus .MustNewConstMetric (
647
+ usersPrivileges , prometheus .GaugeValue , float64 (usersAdminCount ), "admin" ,
648
+ )
649
+
650
+ ch <- prometheus .MustNewConstMetric (
651
+ usersPrivileges , prometheus .GaugeValue , float64 (usersRegularCount ), "user" ,
652
+ )
653
+
584
654
log .Info ("Endpoint scraped and metrics updated" )
585
655
}
586
656
0 commit comments