-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_snmp_process.go
39 lines (36 loc) · 1.7 KB
/
check_snmp_process.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//go:build !client
package request
import (
"context"
"fmt"
"github.com/RincewindsHat/thola/internal/network"
"github.com/RincewindsHat/thola/internal/utility"
"github.com/inexio/go-monitoringplugin"
)
func (r *CheckSNMPRequest) process(ctx context.Context) (Response, error) {
r.init()
r.mon.SetOutputDelimiter(" - ")
var res CheckSNMPResponse
con, err := r.setupSNMPConnection(ctx)
if !r.mon.UpdateStatusOnError(err, monitoringplugin.CRITICAL, "failed to create snmp connection", false) {
version := con.SnmpClient.GetVersion()
if version == "3" {
res.SuccessfulSnmpCredentials = &network.SNMPCredentials{
Version: version,
Port: con.SnmpClient.GetPort(),
V3Level: utility.IfThenElse(con.SnmpClient.GetV3Level() == nil, "", *con.SnmpClient.GetV3Level()).(string),
V3ContextName: utility.IfThenElse(con.SnmpClient.GetV3ContextName() == nil, "", *con.SnmpClient.GetV3ContextName()).(string),
}
r.mon.UpdateStatus(monitoringplugin.OK, fmt.Sprintf("version: '%s'; port: '%d'; level: '%s'; context_name: '%s'", res.SuccessfulSnmpCredentials.Version, res.SuccessfulSnmpCredentials.Port, res.SuccessfulSnmpCredentials.V3Level, res.SuccessfulSnmpCredentials.V3ContextName))
} else {
res.SuccessfulSnmpCredentials = &network.SNMPCredentials{
Version: con.SnmpClient.GetVersion(),
Community: con.SnmpClient.GetCommunity(),
Port: con.SnmpClient.GetPort(),
}
r.mon.UpdateStatus(monitoringplugin.OK, fmt.Sprintf("version: '%s'; community: '%s'; port: '%d'", res.SuccessfulSnmpCredentials.Version, res.SuccessfulSnmpCredentials.Community, res.SuccessfulSnmpCredentials.Port))
}
}
res.CheckResponse = CheckResponse{r.mon.GetInfo()}
return &res, nil
}