def MemoryMsg(): memory = x.MemoryUsage() percent = memory['percent'] warn = cf.yamls['memory']['warning'] crit = cf.yamls['memory']['critical'] memory_q = db.db.search(db.query['memory']) if len(memory_q) < 1: record = db.DB('memory', 'percent', percent, 'False') db.db.insert(record) else: memory_q = (memory_q[-1]) p = memory_q['memory']['percent'] f = memory_q['memory']['flag'] if p >= crit: danger = msg.MemoryPercent(memory['percent'], hostname)[2] alert.Slack(danger, 'Alarm', 'danger', 'high', str(date)) record = db.DB('memory', 'percent', percent, 'True') db.db.insert(record) if p >= warn and p < crit: warning = msg.MemoryPercent(memory['percent'], hostname)[1] alert.Slack(warning, 'Alarm', 'warning', 'medium', str(date)) record = db.DB('memory', 'percent', percent, 'True') db.db.insert(record) if p < warn and f == db.flag: normal = msg.MemoryPercent(memory['percent'], hostname)[0] alert.Slack(normal, 'Alarm', 'good', 'low', str(date)) record = db.DB('memory', 'percent', percent, 'False') db.db.insert(record) if p < warn and f != db.flag: nothing = "Will do nothing"
def SslValidate(): domains = GetDomains('ssl') norm = cf.yamls['ssl_validate']['normal'] warn = cf.yamls['ssl_validate']['warning'] for domain in domains: expire_date = do.ssl_check(domain) remaining = expire_date - today ssl_query = db.db.search(db.query[domain]) if len(ssl_query) < 1: record = db.DB(domain, 'remaining', remaining.days, 'False') db.db.insert(record) else: ssl_query = (ssl_query[-1]) f = ssl_query[domain]['flag'] if remaining.days < warn: warning = msg.SslChek(domain, remaining.days)[1] alert.Slack(warning, 'Alarm', 'danger', 'high', str(date)) record = db.DB(domain, 'remaining', remaining.days, 'True') db.db.insert(record) if remaining.days > norm and f == db.flag: normal = msg.SslChek(domain, remaining.days)[0] alert.Slack(normal, 'Alarm', 'good', 'normal', str(date)) record = db.DB(domain, 'remaining', remaining.days, 'False') db.db.insert(record) if remaining.days > norm and f != db.flag: nothing = "Will do nothing"
def CpuMsg(): average = GetCpuAvg() warn = cf.yamls['cpu']['warning'] crit = cf.yamls['cpu']['critical'] cpu_q = db.db.search(db.query['cpu']) if len(cpu_q) < 1: record = db.DB('cpu', 'average', average, 'False') db.db.insert(record) else: cpu_q = (cpu_q[-1]) p = cpu_q['cpu']['average'] f = cpu_q['cpu']['flag'] if p >= crit: danger = msg.CpuLoadAvg(str(average), hostname)[2] alert.Slack(danger, 'Alarm', 'danger', 'high', str(date)) record = db.DB('cpu', 'average', average, 'True') db.db.insert(record) if p >= warn and p < crit: warning = msg.CpuLoadAvg(str(avarage), hostname)[1] alert.Slack(warning, 'Alarm', 'warning', 'medium', str(date)) record = db.DB('cpu', 'average', average, 'True') db.db.insert(record) if p < warn and f == db.flag: normal = msg.CpuLoadAvg(str(average), hostname)[0] alert.Slack(normal, 'Alarm', 'good', 'low', str(date)) record = db.DB('cpu', 'average', average, 'False') db.db.insert(record) if p < warn and f != db.flag: nothing = "Will do nothing"
def DiskMsg(): partitions = GetDisks() warn = cf.yamls['disk']['warning'] crit = cf.yamls['disk']['critical'] for partition in partitions: percent = x.MapDiskUsage()[partition][3] disk = db.db.search(db.query[partition]) if len(disk) < 1: record = db.DB(partition, 'percent', percent, 'False') db.db.insert(record) else: disk = (disk[-1]) p = disk[partition]['percent'] f = disk[partition]['flag'] if p >= crit: danger = msg.DiskPercent(partition, percent, hostname)[2] alert.Slack(danger, 'Alarm', 'danger', 'high', str(date)) record = db.DB(partition, 'percent', percent, 'True') db.db.insert(record) if p >= warn and p < crit: warning = msg.DiskPercent(partition, percent, hostname)[1] alert.Slack(warning, 'Alarm', 'warning', 'medium', str(date)) record = db.DB(partition, 'percent', percent, 'True') db.db.insert(record) if p < warn and f == db.flag: normal = msg.DiskPercent(partition, percent, hostname)[0] alert.Slack(normal, 'Alarm', 'good', 'low', str(date)) record = db.DB(partition, 'percent', percent, 'False') db.db.insert(record) if p < warn and f != db.flag: nothing = "Will do nothing"
def DomainUptime(): domains = GetDomains('uptime') for domain in domains: dom = db.db.search(db.query[domain]) if len(dom) < 1: record = db.DB(domain, 'status', 'up', 'False') db.db.insert(record) else: dom = (dom[-1]) f = dom[domain]['flag'] try: health = do.url_uptime(domain) if health == 502 or health == 503 or health == 504: down = msg.UrlUp(domain)[1] alert.Slack(down, 'Alarm', 'danger', 'high', str(date)) record = db.DB(domain, 'status', 'down', 'True') db.db.insert(record) if health in range(200, 399) and f == db.flag: up = msg.UrlUp(domain)[0] alert.Slack(up, 'Alarm', 'good', 'normal', str(date)) record = db.DB(domain, 'status', 'up', 'False') db.db.insert(record) if health in range(200, 399) and f != db.flag: nothing = "Will do nothing" except do.requests.exceptions.ConnectionError: notvalid = msg.UrlUp(domain)[2] alert.Slack(notvalid, 'Alarm', 'warning', 'medium', str(date))
def SwapMsg(): swap = x.Swap() percent = swap['percent'] warn = cf.yamls['swap']['warning'] crit = cf.yamls['swap']['critical'] swap_q = db.db.search(db.query['swap']) if len(swap_q) < 1: record = db.DB('swap', 'percent', percent, 'False') db.db.insert(record) else: swap_q = (swap_q[-1]) p = swap_q['swap']['percent'] f = swap_q['swap']['flag'] if p >= crit: danger = msg.SwapPercent(swap['percent'], hostname)[2] alert.Slack(danger, 'Alarm', 'danger', 'high', str(date)) record = db.DB('swap', 'percent', percent, 'True') db.db.insert(record) if p >= warn and p < crit: warning = msg.SwapPercent(swap['percent'], hostname)[1] alert.Slack(warning, 'Alarm', 'warning', 'medium', str(date)) record = db.DB('swap', 'percent', percent, 'True') db.db.insert(record) if p < warn and f == db.flag: normal = msg.SwapPercent(swap['percent'], hostname)[0] alert.Slack(normal, 'Alarm', 'good', 'low', str(date)) record = db.DB('swap', 'percent', percent, 'False') db.db.insert(record) if p < warn and f != db.flag: nothing = "Will do nothing"
def CpuMsg(): cpu = GetCpuAvg() critical = cf.yamls['cpu']['warning'] if cpu >= critical: danger = msg.CpuLoadAvg(str(cpu), hostname) return alert.Slack(danger, 'Alarm', 'danger', 'high', str(date))
def DiskMsg(): partitions = GetDisks() for partition in partitions: percent = x.MapDiskUsage()[partition][3] if percent >= 90: health = partition warn = msg.DiskPercent(partition, percent, hostname) return alert.Slack(warn, 'Alarm', 'danger', 'high', str(date))
def SwapMsg(): swap = x.Swap() if swap['percent'] >= 90: danger = msg.SwapPercent(swap['percent'], hostname) return alert.Slack(danger, 'Alarm', 'danger', 'high', str(date))
def MemoryMsg(): memory = x.MemoryUsage() if memory['percent'] >= 90: danger = msg.MemoryPercent(memory['percent'], hostname) return alert.Slack(danger, 'Alarm', 'danger', 'high', str(date))