forked from sonic-net/sonic-utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtempershow
61 lines (49 loc) · 2.03 KB
/
tempershow
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
#!/usr/bin/env python3
"""
Script to show fan status.
"""
from tabulate import tabulate
from swsscommon.swsscommon import SonicV2Connector
from natsort import natsorted
header = ['Sensor', 'Temperature', 'High TH', 'Low TH', 'Crit High TH', 'Crit Low TH', 'Warning', 'Timestamp']
TEMPER_TABLE_NAME = 'TEMPERATURE_INFO'
TEMPER_FIELD_NAME = 'temperature'
TIMESTAMP_FIELD_NAME = 'timestamp'
HIGH_THRESH_FIELD_NAME = 'high_threshold'
LOW_THRESH_FIELD_NAME = 'low_threshold'
CRIT_HIGH_THRESH_FIELD_NAME = 'critical_high_threshold'
CRIT_LOW_THRESH_FIELD_NAME = 'critical_low_threshold'
WARNING_STATUS_FIELD_NAME = 'warning_status'
class TemperShow(object):
def __init__(self):
self.db = SonicV2Connector(host="127.0.0.1")
self.db.connect(self.db.STATE_DB)
def show(self):
keys = self.db.keys(self.db.STATE_DB, TEMPER_TABLE_NAME + '*')
if not keys:
print('Thermal Not detected\n')
return
table = []
for key in natsorted(keys):
key_list = key.split('|')
if len(key_list) != 2: # error data in DB, log it and ignore
print('Warn: Invalid key in table {}: {}'.format(TEMPER_TABLE_NAME, key))
continue
name = key_list[1]
data_dict = self.db.get_all(self.db.STATE_DB, key)
table.append((name,
data_dict[TEMPER_FIELD_NAME],
data_dict[HIGH_THRESH_FIELD_NAME],
data_dict[LOW_THRESH_FIELD_NAME],
data_dict[CRIT_HIGH_THRESH_FIELD_NAME],
data_dict[CRIT_LOW_THRESH_FIELD_NAME],
data_dict[WARNING_STATUS_FIELD_NAME],
data_dict[TIMESTAMP_FIELD_NAME]
))
if table:
print(tabulate(table, header, tablefmt='simple', stralign='right'))
else:
print('No tempeature data available\n')
if __name__ == "__main__":
temperShow = TemperShow()
temperShow.show()