Checks for max con and each load balancing rule - source ip, ports and destination ips and ports. Also checks for http mode. Does not check for stickiness policies.
()
| 120 | |
| 121 | |
| 122 | def main(): |
| 123 | ''' |
| 124 | Checks for max con and each load balancing rule - source ip, ports and destination |
| 125 | ips and ports. Also checks for http mode. Does not check for stickiness policies. |
| 126 | ''' |
| 127 | haproxyData = getHealthChecksData("haproxyData") |
| 128 | if haproxyData is None or len(haproxyData) == 0: |
| 129 | print("No data provided to check, skipping") |
| 130 | exit(0) |
| 131 | |
| 132 | with open("/etc/haproxy/haproxy.cfg", 'r') as haCfgFile: |
| 133 | haCfgLines = haCfgFile.readlines() |
| 134 | haCfgFile.close() |
| 135 | |
| 136 | if len(haCfgLines) == 0: |
| 137 | print("Unable to read config file /etc/haproxy/haproxy.cfg") |
| 138 | exit(1) |
| 139 | |
| 140 | haCfgSections = {} |
| 141 | currSection = None |
| 142 | currSectionDict = {} |
| 143 | for line in haCfgLines: |
| 144 | line = line.strip() |
| 145 | if len(line) == 0: |
| 146 | if currSection is not None and len(currSectionDict) > 0: |
| 147 | haCfgSections[currSection] = currSectionDict |
| 148 | |
| 149 | currSection = None |
| 150 | currSectionDict = {} |
| 151 | continue |
| 152 | |
| 153 | if currSection is None: |
| 154 | currSection = line |
| 155 | else: |
| 156 | lineSec = line.split(' ', 1) |
| 157 | if lineSec[0] not in currSectionDict: |
| 158 | currSectionDict[lineSec[0]] = [] |
| 159 | |
| 160 | currSectionDict[lineSec[0]].append(lineSec[1] if len(lineSec) > 1 else '') |
| 161 | |
| 162 | checkMaxConn = checkMaxconn(haproxyData[0], haCfgSections) |
| 163 | checkIdleTimeout = checkIdletimeout(haproxyData[0], haCfgSections) |
| 164 | checkLbRules = checkLoadBalance(haproxyData, haCfgSections) |
| 165 | |
| 166 | if checkMaxConn and checkIdleTimeout and checkLbRules: |
| 167 | print("All checks pass") |
| 168 | exit(0) |
| 169 | else: |
| 170 | exit(1) |
| 171 | |
| 172 | |
| 173 | if __name__ == "__main__": |
no test coverage detected