From 1723a32ed83a3019dd6655da857d3f1b7dd0651c Mon Sep 17 00:00:00 2001 From: Tommi2Day Date: Wed, 11 Dec 2024 21:13:04 +0100 Subject: [PATCH] refactor: rework notification ignored output --- README.md | 13 ++++++------- cmd/notification.go | 9 ++++++--- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 3a54299..a60e4fd 100644 --- a/README.md +++ b/README.md @@ -3,11 +3,9 @@ Tool and Nagios/Icinga check plugin for Homematic/Raspberrymatic based on XMLAPI AddOn -[![Go Report Card](https://goreportcard.com/badge/github.com/tommi2day/hmcli)](https://goreportcard.com/report/github.com/tommi2day/hmcli) -![CI](https://github.com/tommi2day/hmcli/actions/workflows/main.yml/badge.svg) -[![codecov](https://codecov.io/gh/Tommi2Day/hmcli/branch/main/graph/badge.svg?token=3EBK75VLC8)](https://codecov.io/gh/Tommi2Day/hmcli) -![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/tommi2day/hmcli) - +[![pipeline status](https://gitlab.intern.tdressler.net/goproj/hmcli/badges/main/pipeline.svg)](https://gitlab.intern.tdressler.net/goproj/hmcli/-/pipelines) +[![coverage report](https://gitlab.intern.tdressler.net/goproj/hmcli/badges/main/coverage.svg?min_medium=50&min_acceptable=75&min_good=90)](https://gitlab.intern.tdressler.net/goproj/hmcli/-/commits/main) +[![Latest Release](https://gitlab.intern.tdressler.net/goproj/hmcli/-/badges/release.svg)](https://gitlab.intern.tdressler.net/goproj/hmcli/-/releases) ## Setup @@ -264,13 +262,14 @@ CONFIG_PENDING: HmIP-RF.000955699D3D84:0.CONFIG_PENDING(Bewegungsmelder Garage) # check notifications as before, but ignore sticky and config pending notifications >hmcli.exe notifications -I 'STICKY|PENDING' -w 1 -0 notifications pending, 1 ignored | 'notifications'=0;1;;; 'time'=1853ms;;;; +0 notifications pending | 'notifications'=0;1;;; 'time'=1853ms;;;; # print ignored notifications >hmcli.exe notifications -I 'STICKY|PENDING' -p 0 notifications pending, 1 ignored | 'notifications'=0;;;; 'time'=1764ms;;;; -IGNORED: CONFIG_PENDING: HmIP-RF.000955699D3D84:0.CONFIG_PENDING(Bewegungsmelder Garage) since 2024-02-17T18:25:31+01:00 +IGNORED: +CONFIG_PENDING: HmIP-RF.000955699D3D84:0.CONFIG_PENDING(Bewegungsmelder Garage) since 2024-02-17T18:25:31+01:00 # list rssi values of devices >hmcli.exe rssi Address:BidCoS-RF rx:65536 tx: -56 diff --git a/cmd/notification.go b/cmd/notification.go index 746a2cc..a5a05cc 100644 --- a/cmd/notification.go +++ b/cmd/notification.go @@ -58,7 +58,7 @@ func getNotifications(cmd *cobra.Command, _ []string) error { return nil } - if _, err := hmlib.GetStateList(); err != nil { + if _, err = hmlib.GetStateList(); err != nil { return err } @@ -81,6 +81,7 @@ func processNotifications(notifications hmlib.SystemNotificationResponse, reIgno notificationCount := len(notifications.Notifications) ignoredCount := 0 notificationDetails := "" + ignoredDetails := "" for _, notification := range notifications.Notifications { details, err := processNotificationDetail(notification) @@ -95,11 +96,12 @@ func processNotifications(notifications hmlib.SystemNotificationResponse, reIgno if reIgnoreNotifications != nil && reIgnoreNotifications.MatchString(output) { log.Debugf("ignoring notification: %s", output) notificationCount-- - ignoredCount++ if !printIgnored { continue } - output = ignoredPrefix + output + ignoredCount++ + ignoredDetails += output + output = "" } notificationDetails += output } @@ -107,6 +109,7 @@ func processNotifications(notifications hmlib.SystemNotificationResponse, reIgno finalOutput := fmt.Sprintf("%d notifications pending", notificationCount) if ignoredCount > 0 { finalOutput += fmt.Sprintf(", %d ignored", ignoredCount) + notificationDetails += fmt.Sprintf("%s\n%s", ignoredPrefix, ignoredDetails) } perfdata := []nagios.PerformanceData{