| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package nagios |
| 4 | |
| 5 | import "github.com/netdata/netdata/go/plugins/pkg/metrix" |
| 6 | |
| 7 | const ( |
| 8 | perfFieldValue = "value" |
| 9 | perfThresholdStateNone = "no_threshold" |
| 10 | perfThresholdStateOK = "ok" |
| 11 | perfThresholdStateWarning = "warning" |
| 12 | perfThresholdStateCritical = "critical" |
| 13 | perfThresholdStateRetry = "retry" |
| 14 | perfdataValueLabelKey = "perfdata_value" |
| 15 | jobPerfdataThresholdMetricName = "job.perfdata.threshold_state" |
| 16 | ) |
| 17 | |
| 18 | var ( |
| 19 | perfThresholdStateNames = []string{ |
| 20 | perfThresholdStateNone, |
| 21 | perfThresholdStateOK, |
| 22 | perfThresholdStateWarning, |
| 23 | perfThresholdStateCritical, |
| 24 | } |
| 25 | perfThresholdAlertStateNames = []string{ |
| 26 | perfThresholdStateNone, |
| 27 | perfThresholdStateOK, |
| 28 | perfThresholdStateWarning, |
| 29 | perfThresholdStateCritical, |
| 30 | perfThresholdStateRetry, |
| 31 | } |
| 32 | ) |
| 33 | |
| 34 | type perfValueMeasureSet struct { |
| 35 | name string |
| 36 | checkName string |
| 37 | unit string |
| 38 | counter bool |
| 39 | value metrix.SampleValue |
| 40 | } |
| 41 | |
| 42 | type perfThresholdStateSet struct { |
| 43 | name string |
| 44 | checkName string |
| 45 | perfdataValue string |
| 46 | state string |
| 47 | } |
| 48 | |
| 49 | type perfRouteResult struct { |
| 50 | values []perfValueMeasureSet |
| 51 | thresholdStates []perfThresholdStateSet |
| 52 | } |
| 53 | |
| 54 | func perfMeasureSetFieldSpecs() []metrix.MeasureFieldSpec { |
| 55 | return []metrix.MeasureFieldSpec{ |
| 56 | {Name: perfFieldValue, Float: true}, |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | func perfMeasureFieldFloat(field string) bool { |
| 61 | return field == perfFieldValue |
| 62 | } |
| 63 | |
| 64 | func defaultPerfMeasureSetValues() map[string]metrix.SampleValue { |
| 65 | return map[string]metrix.SampleValue{perfFieldValue: 0} |
| 66 | } |
| 67 | |
| 68 | func perfMeasureSetValues(value metrix.SampleValue) map[string]metrix.SampleValue { |
| 69 | return map[string]metrix.SampleValue{perfFieldValue: value} |
| 70 | } |
| 71 | |
| 72 | func perfThresholdStatePoint(active string) metrix.StateSetPoint { |
| 73 | return stateSetPoint(perfThresholdStateNames, active) |
| 74 | } |
| 75 | |
| 76 | func perfThresholdAlertStatePoint(actives ...string) metrix.StateSetPoint { |
| 77 | return stateSetPoint(perfThresholdAlertStateNames, actives...) |
| 78 | } |
| 79 | |
| 80 | func stateSetPoint(names []string, actives ...string) metrix.StateSetPoint { |
| 81 | states := make(map[string]bool, len(names)) |
| 82 | for _, state := range names { |
| 83 | states[state] = false |
| 84 | } |
| 85 | for _, active := range actives { |
| 86 | if active == "" { |
| 87 | continue |
| 88 | } |
| 89 | states[active] = true |
| 90 | } |
| 91 | return metrix.StateSetPoint{States: states} |
| 92 | } |