1 | <?php |
||||
2 | |||||
3 | use Illuminate\Support\Str; |
||||
4 | |||||
5 | echo ' ENTITY-SENSOR: '; |
||||
6 | echo 'Caching OIDs:'; |
||||
7 | if (empty($entity_array)) { |
||||
8 | $entity_array = []; |
||||
9 | echo ' entPhysicalDescr'; |
||||
10 | $entity_array = snmpwalk_cache_multi_oid($device, 'entPhysicalDescr', $entity_array, 'ENTITY-MIB'); |
||||
11 | if (! empty($entity_array)) { |
||||
12 | echo ' entPhysicalName'; |
||||
13 | $entity_array = snmpwalk_cache_multi_oid($device, 'entPhysicalName', $entity_array, 'ENTITY-MIB'); |
||||
14 | } |
||||
15 | } |
||||
16 | |||||
17 | if (! empty($entity_array)) { |
||||
18 | echo ' entPhySensorType'; |
||||
19 | $entity_oids = snmpwalk_cache_multi_oid($device, 'entPhySensorType', [], 'ENTITY-SENSOR-MIB'); |
||||
20 | echo ' entPhySensorScale'; |
||||
21 | $entity_oids = snmpwalk_cache_multi_oid($device, 'entPhySensorScale', $entity_oids, 'ENTITY-SENSOR-MIB'); |
||||
22 | echo ' entPhySensorPrecision'; |
||||
23 | $entity_oids = snmpwalk_cache_multi_oid($device, 'entPhySensorPrecision', $entity_oids, 'ENTITY-SENSOR-MIB'); |
||||
24 | echo ' entPhySensorValue'; |
||||
25 | $entity_oids = snmpwalk_cache_multi_oid($device, 'entPhySensorValue', $entity_oids, 'ENTITY-SENSOR-MIB'); |
||||
26 | if ($device['os'] === 'arista_eos') { |
||||
27 | $entity_oids = snmpwalk_cache_oid($device, 'aristaEntSensorThresholdTable', $entity_oids, 'ARISTA-ENTITY-SENSOR-MIB'); |
||||
28 | } |
||||
29 | echo ' entPhySensorOperStatus'; |
||||
30 | $entity_oids = snmpwalk_cache_multi_oid($device, 'entPhySensorOperStatus', $entity_oids, 'ENTITY-SENSOR-MIB'); |
||||
31 | } |
||||
32 | |||||
33 | if (! empty($entity_oids)) { |
||||
34 | $entitysensor = [ |
||||
35 | 'voltsDC' => 'voltage', |
||||
36 | 'voltsAC' => 'voltage', |
||||
37 | 'amperes' => 'current', |
||||
38 | 'watts' => 'power', |
||||
39 | 'hertz' => 'freq', |
||||
40 | 'percentRH' => 'humidity', |
||||
41 | 'rpm' => 'fanspeed', |
||||
42 | 'celsius' => 'temperature', |
||||
43 | 'dBm' => 'dbm', |
||||
44 | ]; |
||||
45 | |||||
46 | foreach ($entity_oids as $index => $entry) { |
||||
47 | $low_limit = null; |
||||
48 | $low_warn_limit = null; |
||||
49 | $warn_limit = null; |
||||
50 | $high_limit = null; |
||||
51 | |||||
52 | // Fix for Cisco ASR920, 15.5(2)S |
||||
53 | if ($entry['entPhySensorType'] == 'other' && Str::contains($entity_array[$index]['entPhysicalName'], ['Rx Power Sensor', 'Tx Power Sensor'])) { |
||||
54 | $entitysensor['other'] = 'dbm'; |
||||
55 | } |
||||
56 | if ($entitysensor[$entry['entPhySensorType']] && is_numeric($entry['entPhySensorValue']) && is_numeric($index)) { |
||||
57 | $entPhysicalIndex = $index; |
||||
58 | $oid = '.1.3.6.1.2.1.99.1.1.1.4.' . $index; |
||||
59 | $current = $entry['entPhySensorValue']; |
||||
60 | if ($device['os'] === 'arris-d5') { |
||||
61 | $card = str_split($index); |
||||
62 | if (count($card) === 3) { |
||||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
63 | $card = $card[0] . '00'; |
||||
64 | } elseif (count($card) === 4) { |
||||
65 | $card = $card[0] . $card[1] . '00'; |
||||
66 | } |
||||
67 | $descr = ucwords($entity_array[$card]['entPhysicalName']) . ' ' . ucwords($entity_array[$index]['entPhysicalDescr']); |
||||
68 | } else { |
||||
69 | $descr = ucwords($entity_array[$index]['entPhysicalName']); |
||||
70 | } |
||||
71 | if ($descr) { |
||||
72 | $descr = rewrite_entity_descr($descr); |
||||
73 | } else { |
||||
74 | // Better sensor names for Arista EOS. Remove some redundancy and improve them so they reflect to which unit they belong. |
||||
75 | if ($device['os'] === 'arista_eos') { |
||||
76 | $descr = $entity_array[$index]['entPhysicalDescr']; |
||||
77 | if (preg_match('/(Input|Output) (voltage|current) sensor/i', $descr) || Str::startsWith($descr, 'Power supply') || preg_match('/^(Power Supply|Hotspot|Inlet|Board)/i', $descr)) { |
||||
78 | $descr = ucwords($entity_array[substr_replace($index, '000', -3)]['entPhysicalDescr']) . ' ' . preg_replace('/(Voltage|Current|Power Supply) Sensor$/i', '', ucwords($entity_array[$index]['entPhysicalDescr'])); |
||||
79 | } |
||||
80 | if (preg_match('/(temp|temperature) sensor$/i', $descr)) { |
||||
81 | $descr = preg_replace('/(temp|temperature) sensor$/i', '', $descr); |
||||
82 | } |
||||
83 | } |
||||
84 | // End better sensor names for Arista EOS. |
||||
85 | $descr = rewrite_entity_descr($descr); |
||||
86 | } |
||||
87 | $valid_sensor = check_entity_sensor($descr, $device); |
||||
0 ignored issues
–
show
It seems like
$descr can also be of type string ; however, parameter $string of check_entity_sensor() does only seem to accept value , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
88 | $type = $entitysensor[$entry['entPhySensorType']]; |
||||
89 | // FIXME this stuff is foul |
||||
90 | if ($entry['entPhySensorScale'] == 'nano') { |
||||
91 | $divisor = '1000000000'; |
||||
92 | $multiplier = '1'; |
||||
93 | } |
||||
94 | if ($entry['entPhySensorScale'] == 'micro') { |
||||
95 | $divisor = '1000000'; |
||||
96 | $multiplier = '1'; |
||||
97 | } |
||||
98 | if ($entry['entPhySensorScale'] == 'milli') { |
||||
99 | $divisor = '1000'; |
||||
100 | $multiplier = '1'; |
||||
101 | } |
||||
102 | if ($entry['entPhySensorScale'] == 'units') { |
||||
103 | $divisor = '1'; |
||||
104 | $multiplier = '1'; |
||||
105 | } |
||||
106 | if ($entry['entPhySensorScale'] == 'kilo') { |
||||
107 | $divisor = '1'; |
||||
108 | $multiplier = '1000'; |
||||
109 | } |
||||
110 | if ($entry['entPhySensorScale'] == 'mega') { |
||||
111 | $divisor = '1'; |
||||
112 | $multiplier = '1000000'; |
||||
113 | } |
||||
114 | if ($entry['entPhySensorScale'] == 'giga') { |
||||
115 | $divisor = '1'; |
||||
116 | $multiplier = '1000000000'; |
||||
117 | } |
||||
118 | if ($entry['entPhySensorScale'] == 'yocto') { |
||||
119 | $divisor = '1'; |
||||
120 | $multiplier = '1'; |
||||
121 | } |
||||
122 | if (is_numeric($entry['entPhySensorPrecision']) && $entry['entPhySensorPrecision'] > '0') { |
||||
123 | $divisor = $divisor . str_pad('', $entry['entPhySensorPrecision'], '0'); |
||||
124 | } |
||||
125 | |||||
126 | $current = ($current * $multiplier / $divisor); |
||||
127 | if ($type == 'temperature') { |
||||
128 | if ($current > '200') { |
||||
129 | $valid_sensor = false; |
||||
130 | } |
||||
131 | $descr = preg_replace('/[T|t]emperature[|s]/', '', $descr); |
||||
132 | } |
||||
133 | if ($device['os'] == 'rittal-lcp') { |
||||
134 | if ($type == 'voltage') { |
||||
135 | $divisor = 1000; |
||||
136 | } |
||||
137 | if ($descr == 'Temperature.Value') { |
||||
138 | $divisor = 1000; |
||||
139 | } |
||||
140 | if ($descr == 'System.Temperature.Value') { |
||||
141 | $divisor = 1000; |
||||
142 | } |
||||
143 | if ($type == 'humidity' && $current == '0') { |
||||
144 | $valid_sensor = false; |
||||
145 | } |
||||
146 | } |
||||
147 | if ($current == '-127' || ($device['os'] == 'asa' && Str::endsWith($device['hardware'], 'sc'))) { |
||||
148 | $valid_sensor = false; |
||||
149 | } |
||||
150 | // Check for valid sensors |
||||
151 | if ($entry['entPhySensorOperStatus'] === 'unavailable') { |
||||
152 | $valid_sensor = false; |
||||
153 | } |
||||
154 | if ($valid_sensor && dbFetchCell("SELECT COUNT(*) FROM `sensors` WHERE device_id = ? AND `sensor_class` = ? AND `sensor_type` = 'cisco-entity-sensor' AND `sensor_index` = ?", [$device['device_id'], $type, $index]) == '0') { |
||||
155 | // Check to make sure we've not already seen this sensor via cisco's entity sensor mib |
||||
156 | if ($type == 'power' && $device['os'] == 'arista_eos' && preg_match('/DOM (R|T)x Power/i', $descr)) { |
||||
157 | $type = 'dbm'; |
||||
158 | $current = round(10 * log10($entry['entPhySensorValue'] / 10000), 3); |
||||
159 | $multiplier = 1; |
||||
160 | $divisor = 1; |
||||
161 | } |
||||
162 | |||||
163 | if ($device['os'] === 'arista_eos') { |
||||
164 | if ($entry['aristaEntSensorThresholdLowWarning'] != '-1000000000') { |
||||
165 | if ($entry['entPhySensorScale'] == 'milli' && $entry['entPhySensorType'] == 'watts') { |
||||
166 | $temp_low_warn_limit = $entry['aristaEntSensorThresholdLowWarning'] / 10000; |
||||
167 | $low_warn_limit = round(10 * log10($temp_low_warn_limit), 2); |
||||
168 | } else { |
||||
169 | $low_warn_limit = $entry['aristaEntSensorThresholdLowWarning'] / $divisor; |
||||
170 | } |
||||
171 | } |
||||
172 | if ($entry['aristaEntSensorThresholdLowCritical'] != '-1000000000') { |
||||
173 | if ($entry['entPhySensorScale'] == 'milli' && $entry['entPhySensorType'] == 'watts') { |
||||
174 | $temp_low_limit = $entry['aristaEntSensorThresholdLowCritical'] / 10000; |
||||
175 | $low_limit = round(10 * log10($temp_low_limit), 2); |
||||
176 | } else { |
||||
177 | $low_limit = $entry['aristaEntSensorThresholdLowCritical'] / $divisor; |
||||
178 | } |
||||
179 | } |
||||
180 | if ($entry['aristaEntSensorThresholdHighWarning'] != '1000000000') { |
||||
181 | if ($entry['entPhySensorScale'] == 'milli' && $entry['entPhySensorType'] == 'watts') { |
||||
182 | $temp_warn_limit = $entry['aristaEntSensorThresholdHighWarning'] / 10000; |
||||
183 | $warn_limit = round(10 * log10($temp_warn_limit), 2); |
||||
184 | } else { |
||||
185 | $warn_limit = $entry['aristaEntSensorThresholdHighWarning'] / $divisor; |
||||
186 | } |
||||
187 | } |
||||
188 | if ($entry['aristaEntSensorThresholdHighCritical'] != '1000000000') { |
||||
189 | if ($entry['entPhySensorScale'] == 'milli' && $entry['entPhySensorType'] == 'watts') { |
||||
190 | $temp_high_limit = $entry['aristaEntSensorThresholdHighCritical'] / 10000; |
||||
191 | $high_limit = round(10 * log10($temp_high_limit), 2); |
||||
192 | } else { |
||||
193 | $high_limit = $entry['aristaEntSensorThresholdHighCritical'] / $divisor; |
||||
194 | } |
||||
195 | } |
||||
196 | // Grouping sensors |
||||
197 | $group = null; |
||||
198 | if (preg_match('/DOM /i', $descr)) { |
||||
199 | $group = 'SFPs'; |
||||
200 | } elseif (preg_match('/PwrCon/', $descr)) { |
||||
201 | $string = explode(' ', $descr); |
||||
202 | if (preg_match('/PwrCon[0-9]/', $string[0])) { |
||||
203 | $group = $string[0]; |
||||
204 | } else { |
||||
205 | $group = preg_replace('/PwrCon/i', '', $string[0]); |
||||
206 | } |
||||
207 | $descr = preg_replace('/^.*?(PwrCon)[0-9]*/i', '', $descr); |
||||
208 | } elseif (preg_match('/^(Trident.*|Jericho[0-9]|FM6000)/i', $descr)) { |
||||
209 | // I only know replies for Trident|Jericho|FM6000 platform. If you have another please add to the preg_match |
||||
210 | $group = 'Platform'; |
||||
211 | } elseif (preg_match('/^(Power|PSU)/i', $descr)) { |
||||
212 | $group = 'PSUs'; |
||||
213 | } else { |
||||
214 | $group = 'System'; |
||||
215 | $descr = Str::replaceLast('temp sensor', '', $descr); |
||||
216 | } |
||||
217 | // End grouping sensors |
||||
218 | } |
||||
219 | discover_sensor($valid['sensor'], $type, $device, $oid, $index, 'entity-sensor', $descr, $divisor, $multiplier, $low_limit, $low_warn_limit, $warn_limit, $high_limit, $current, 'snmp', $entPhysicalIndex, $entry['entSensorMeasuredEntity'], null, $group); |
||||
220 | } |
||||
221 | }//end if |
||||
222 | }//end foreach |
||||
223 | unset( |
||||
224 | $entity_array |
||||
225 | ); |
||||
226 | }//end if |
||||
227 | echo "\n"; |
||||
228 |