Skip to content

Commit

Permalink
Fixing bugs and refactor config
Browse files Browse the repository at this point in the history
  • Loading branch information
OldTyT committed Nov 25, 2022
1 parent bd38655 commit a19a8f9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ Default path to config - `$HOME/.config/alerta_notify.json`
* `alerta.password` - User password from [Alerta](https://github.com/alerta/alerta).
* `alerta.url` - URL Address [Alerta](https://github.com/alerta/alerta).
* `alerta.query` - Request to [Alerta](https://github.com/alerta/alerta) by which alerts will be received.
* `path.icon_notify` - The path to the icon, for notification. It does not work on all operating systems.
* `path.icon_alert` - The path to the icon, for alerts notification. It does not work on all operating systems.
* `path.sound_notify` - Path to sound file for notify message. To turn off the sound, specify a non-existent file and ignore the errors.
* `path.sound_alert` - Path to sound file for alert.
* `path.icon.notify` - The path to the icon, for notification. It does not work on all operating systems.
* `path.icon.alert` - The path to the icon, for alerts notification. It does not work on all operating systems.
* `path.sound.notify` - Path to sound file for notify message. To turn off the sound, specify a non-existent file and ignore the errors.
* `path.sound.alert` - Path to sound file for alert.
* `time_sleep` - Sleep time between iterations, in seconds.
12 changes: 8 additions & 4 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
"query": "/alerts?sort-by=lastReceiveTime&status=open&status=unknown"
},
"path": {
"icon_notify": "path/to/icon.png",
"icon_alert": "path/to/icon.png",
"sound_notify": "/usr/share/sounds/freedesktop/stereo/bell.oga",
"sound_alert": "/usr/share/sounds/freedesktop/stereo/alarm-clock-elapsed.oga"
"icon": {
"notify": "/usr/share/doc/HTML/en/kcontrol/windowspecific/Face-smile.png",
"alert": "/usr/share/doc/HTML/en/khangman/application-exit.png"
},
"sound": {
"notify": "/usr/share/sounds/freedesktop/stereo/bell.oga",
"alert": "/usr/share/sounds/freedesktop/stereo/alarm-clock-elapsed.oga"
}
},
"time_sleep": 30
}
11 changes: 7 additions & 4 deletions internal/vars/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ type NotifierCFG struct {
}

type PathStruct struct {
IconNotify string `json:"icon_notify"`
IconAlert string `json:"icon_alert"`
SoundNotify string `json:"sound_notify"`
SoundAlert string `json:"sound_alert"`
Icon NotifyAlert `json:"icon"`
Sound NotifyAlert `json:"sound"`
}

type NotifyAlert struct {
Notify string `json:"notify"`
Alert string `json:"alert"`
}

type AlertaStuct struct {
Expand Down
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func ViewSummary() {
}

func ErrorExiting(ErrorMsg string) {
notify.Alert("Alerta notify", "Alerta Notify", ErrorMsg, vars.Notifier.Path.IconAlert, vars.Notifier.Path.SoundAlert)
notify.Alert("Alerta notify", "Alerta Notify", ErrorMsg, vars.Notifier.Path.Icon.Alert, vars.Notifier.Path.Sound.Alert)
os.Exit(1)
}

Expand Down Expand Up @@ -98,11 +98,11 @@ func LoginAlerta() {
}

func SendNotify(text string) {
go notify.Notify("Alerta notify", "Alerta Notify", text, vars.Notifier.Path.IconNotify, vars.Notifier.Path.SoundNotify)
go notify.Notify("Alerta notify", "Alerta Notify", text, vars.Notifier.Path.Icon.Notify, vars.Notifier.Path.Sound.Notify)
}

func SendAlert(text string) {
go notify.Alert("Alerta notify", "Alerta Notify", text, vars.Notifier.Path.IconAlert, vars.Notifier.Path.SoundAlert)
go notify.Alert("Alerta notify", "Alerta Notify", text, vars.Notifier.Path.Icon.Alert, vars.Notifier.Path.Sound.Alert)
}

func UpdateAlerts() {
Expand Down Expand Up @@ -150,7 +150,7 @@ func UpdateAlerts() {
SendAlert("Can't unmarshal JSON. " + err.Error())
}
for key := range Alert {
go notify.Alert("Alerta notify", Alert[key].ENV+"/"+Alert[key].Severity, Alert[key].AlertName+"\n"+Alert[key].Resource, vars.Notifier.Path.IconAlert, vars.Notifier.Path.SoundAlert)
go notify.Alert("Alerta notify", Alert[key].ENV+"/"+Alert[key].Severity, Alert[key].AlertName+"\n"+Alert[key].Resource, vars.Notifier.Path.Icon.Alert, vars.Notifier.Path.Sound.Alert)
}
}
}
Expand Down

0 comments on commit a19a8f9

Please sign in to comment.