-
Notifications
You must be signed in to change notification settings - Fork 1
/
systemStatus.go
61 lines (49 loc) · 1.22 KB
/
systemStatus.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) 2018 the check_snmp_authors. All rights reserved.
// Use of this source code is governed by ISC-style license
// that can be found in the LICENSE file.
package check_snmp_synology
import (
"fmt"
"time"
"github.com/sonjah/gosnmp"
)
func CheckSystemStatus(s *gosnmp.GoSNMP, u *Utilities) {
// Required fields
service := "System-Status"
exitcode := CRITICAL
message := ""
perfdata := ""
stateOk := 1
stateCritical := 2
// Fetch SNMP Data
timeFetch := time.Now()
oids := []string{OID_systemStatus}
response, err := s.Get(oids)
u.Metrics.TimeToFetch += time.Now().Sub(timeFetch)
// Errorhandling
if err != nil {
exitcode = UNKNOWN
message = err.Error()
Write(u.Args.Hostname, service, exitcode, message, perfdata, u)
return
}
// Get the result
sysStat := response.Variables[0].Value.(int)
// Set response information
switch sysStat {
case stateOk:
exitcode = OK
message = "Normal"
case stateCritical:
exitcode = OK
message = "Failed"
default:
exitcode = UNKNOWN
message = "Unknown"
}
// Set perfdata
perfdata = fmt.Sprintf("System_Status=%d;;%d", sysStat, stateCritical)
// Done. Write the check result
Write(u.Args.Hostname, service, exitcode, message, perfdata, u)
return
}