Skip to content

Commit

Permalink
refactor: rework notification ignored output
Browse files Browse the repository at this point in the history
  • Loading branch information
Tommi2Day committed Dec 11, 2024
1 parent 90a4ef4 commit 1723a32
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions cmd/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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)
Expand All @@ -95,18 +96,20 @@ 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
}

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{
Expand Down

0 comments on commit 1723a32

Please sign in to comment.