|
29 | 29 | pass |
30 | 30 |
|
31 | 31 | mmsdrfsFile = '/var/mmfs/gen/mmsdrfs' |
32 | | -zimonFile = '/opt/IBM/zimon/ZIMonSensors.cfg' |
| 32 | +zimonFile = '/opt/IBM/zimon' |
33 | 33 | collectorsFile = '/opt/IBM/zimon/ZIMonCollector.cfg' |
34 | 34 |
|
35 | 35 |
|
@@ -57,36 +57,57 @@ def readSensorsConfigFromMMSDRFS(logger=None): |
57 | 57 | return parseSensorsConfig(data, logger) |
58 | 58 |
|
59 | 59 |
|
60 | | -def readSensorsConfig(logger=None): |
| 60 | +def readSensorsConfig(logger=None, customFile=None): |
61 | 61 | ''' |
62 | 62 | :return: list of dictionaries with sensorsName as key and the values of the sensors in the ZimonSensors.cfg |
63 | 63 | ''' |
64 | 64 | if not logger: |
65 | 65 | logger = SysmonLogger.getLogger(__name__) |
66 | 66 |
|
67 | | - if not os.path.isfile(zimonFile): |
| 67 | + global zimonFile |
| 68 | + if customFile: |
| 69 | + zimonFile = rf"{customFile}" |
| 70 | + |
| 71 | + sensorConfigFiles = [] |
| 72 | + parsedSensors = [] |
| 73 | + |
| 74 | + if os.path.isfile(zimonFile): |
| 75 | + sensorConfigFiles.append(zimonFile) |
| 76 | + elif os.path.isdir(zimonFile): |
| 77 | + for root, dirs, files in os.walk(zimonFile): |
| 78 | + for file in files: |
| 79 | + if file.endswith(".cfg"): |
| 80 | + sensorConfigFiles.append(os.path.join(root, file)) |
| 81 | + else: |
68 | 82 | logger.details("ZiMon sensor configuration file not found (%s) ", zimonFile) |
69 | 83 | print("ZiMon sensor configuration file not found") |
70 | 84 | raise OSError(2, 'No such file or directory', zimonFile) |
71 | 85 |
|
72 | 86 | data = "" |
73 | 87 | logger.debug("readSensorsConfig attempt to read %s", zimonFile) |
74 | | - try: |
75 | | - with open(zimonFile) as myfile: |
76 | | - data = myfile.read().replace('\n', '') |
77 | | - except (Exception, IOError) as error: |
78 | | - logger.details("failed trying read %s with reason: %s", zimonFile, error) |
79 | | - return [] |
80 | | - # parse config file in a list of dictionaries format |
81 | | - return parseSensorsConfig(data, logger) |
| 88 | + for file in sensorConfigFiles: |
| 89 | + try: |
| 90 | + with open(file) as myfile: |
| 91 | + data = myfile.read().replace('\n', '') |
| 92 | + except (Exception, IOError) as error: |
| 93 | + logger.details("failed trying read %s with reason: %s", zimonFile, error) |
| 94 | + continue |
| 95 | + # parse config file in a list of dictionaries format |
| 96 | + parsedSensors.extend(parseSensorsConfig(data, logger)) |
| 97 | + return parsedSensors |
82 | 98 |
|
83 | 99 |
|
84 | 100 | def parseSensorsConfig(sensorsConfig, logger): |
85 | 101 | """ Returns a list of dicts, describing definitions of sensors """ |
86 | 102 | logger.debug("invoke parseSensorsConfig") |
87 | 103 | try: |
88 | 104 | sensors = [] |
89 | | - sensorsStr = sensorsConfig[sensorsConfig.find("sensors"):sensorsConfig.find("smbstat")] |
| 105 | + sensorsStr = "" |
| 106 | + if sensorsConfig.find("smbstat") != -1: |
| 107 | + sensorsStr = sensorsConfig[sensorsConfig.find("sensors"):sensorsConfig.find("smbstat")] |
| 108 | + else: |
| 109 | + end = None |
| 110 | + sensorsStr = sensorsConfig[sensorsConfig.find("sensors"):end] |
90 | 111 | sensorsList = re.findall('(?P<sensor>{.*?})(?:,|$)', sensorsStr) |
91 | 112 | for sensorString in sensorsList: |
92 | 113 | sensorAttr = re.findall(r'(?P<name>\w+) = (?P<value>\"\S*\"|\d+)', sensorString) |
|
0 commit comments