From 0cf8c8d99485ab06b09e7ddf92a0dc2cd4da97d5 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 22 Apr 2023 22:29:35 +0300 Subject: print out when there were no status changes or there are no unhandled alerts" --- README.md | 8 ++++---- internal/state.go | 11 +++++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ce4a735..529039d 100644 --- a/README.md +++ b/README.md @@ -15,13 +15,13 @@ This is the recent Gogios report! # Alerts with status changed: -OK->CRITICAL: Check ICMP4 vulcan.buetow.org ==>> Check command timed out -OK->CRITICAL: Check ICMP6 vulcan.buetow.org ==>> Check command timed out +OK->CRITICAL: Check ICMP4 vulcan.buetow.org: Check command timed out +OK->CRITICAL: Check ICMP6 vulcan.buetow.org: Check command timed out # Unhandled alerts: -CRITICAL: Check ICMP4 vulcan.buetow.org ==>> Check command timed out -CRITICAL: Check ICMP6 vulcan.buetow.org ==>> Check command timed out +CRITICAL: Check ICMP4 vulcan.buetow.org: Check command timed out +CRITICAL: Check ICMP6 vulcan.buetow.org: Check command timed out Have a nice day! ``` diff --git a/internal/state.go b/internal/state.go index aaa54e9..3ac8e7d 100644 --- a/internal/state.go +++ b/internal/state.go @@ -92,16 +92,23 @@ func (s state) report(renotify bool) (string, string, bool) { sb.WriteString("# Alerts with status changed:\n\n") changed := s.reportChanged(&sb) + if !changed { + sb.WriteString("There were no status changes...\n\n") + } sb.WriteString("# Unhandled alerts:\n\n") numCriticals, numWarnings, numUnknown, numOK := s.reportUnhandled(&sb) + hasUnhandled := (numCriticals + numWarnings + numUnknown) > 0 + if !hasUnhandled { + sb.WriteString("There are no unhandled alerts...\n\n") + } sb.WriteString("Have a nice day!\n") subject := fmt.Sprintf("GOGIOS Report [C:%d W:%d U:%d OK:%d]", numCriticals, numWarnings, numUnknown, numOK) - return subject, sb.String(), changed || (renotify && (numCriticals+numWarnings+numUnknown) > 0) + return subject, sb.String(), changed || (renotify && hasUnhandled) } func (s state) reportChanged(sb *strings.Builder) (changed bool) { @@ -160,7 +167,7 @@ func (s state) reportBy(sb *strings.Builder, showStatusChange bool, sb.WriteString(nagiosCode(cs.Status).Str()) sb.WriteString(": ") sb.WriteString(name) - sb.WriteString(" ==>> ") + sb.WriteString(": ") sb.WriteString(cs.output) sb.WriteString("\n") } -- cgit v1.2.3