Skip to content

Commit

Permalink
Implement optional notifications
Browse files Browse the repository at this point in the history
Refs #5
  • Loading branch information
algorys committed Jul 15, 2016
1 parent 38e9900 commit bff888e
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 46 deletions.
29 changes: 21 additions & 8 deletions alignak_app/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,39 +285,52 @@ def notify_change(self):
hosts_states, services_states = self.get_state()

message = "Info: all is OK.)"
icon = 'ok'

img = os.path.abspath(
self.Config.get('Config', 'path') +
self.Config.get('Config', 'img') +
'/' +
self.Config.get('Config', 'ok'))
self.change_icon("ok")

# self.change_icon(icon)

if services_states['critical'] <= 0 and hosts_states['down'] <= 0:
if services_states['unknown'] > 0 or services_states['warning'] > 0:
self.change_icon("warning")
icon = 'warning'
message = "Warning: some Services are unknown or warning."
img = os.path.abspath(
self.Config.get('Config', 'path') +
self.Config.get('Config', 'img') +
'/' +
self.Config.get('Config', 'warning'))
elif (services_states['critical'] > 0) or (hosts_states['down'] > 0):
self.change_icon("alert")
icon = 'alert'
message = "Alert: Hosts or Services are DOWN !"
img = os.path.abspath(
self.Config.get('Config', 'path') +
self.Config.get('Config', 'img') +
'/' +
self.Config.get('Config', 'alert'))

Notify.Notification.new(
str(message),
if 'true' in self.Config.get('Alignak-App', 'notifications'):
Notify.Notification.new(
str(message),
self.update_hosts_menu(
hosts_states,
services_states
),
img,
).show()
self.change_icon(icon)
elif 'false' in self.Config.get('Alignak-App', 'notifications'):
self.update_hosts_menu(
hosts_states,
services_states
),
img,
).show()
)
self.change_icon(icon)
else:
print('Bad parameters in config file, [notifications]')

return True

Expand Down
44 changes: 27 additions & 17 deletions etc/settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

; # Frequency
; ------------------------------------------------------------------------------------------
; Defines (in seconds) the frequency of check of the backend API.
; Defines (in seconds) the frequency of check to the backend API.
; Default is 30
check_interval = 30

; # Get Notify
; # Notifications
; ------------------------------------------------------------------------------------------
; Choose if you want notify by popup or not
; Default is yes
; get_notify = yes
; Choose if you want to be notify by popup or not, when something change.
; If you set false, just the icon color change.
; If true, you get desktop notifications for each interval.
; Default is 'true'. Possible values are : 'true' or 'false'
notifications = true

[Backend]
; # Backend authentication
Expand All @@ -33,28 +35,36 @@ backend_url = http://127.0.0.1:5000
webui_url = http://127.0.0.1:5001

[Config]
; # Icon
; ------------------------------------------------------------------------------------------
; This is the icon of alignak-app which is display in your notification area.
; Paste your custom image in "images" folder if you want to change.
icon = alignak.svg
ok = ok.svg
warning = warning.svg
alert = alert.svg

; # Config Path
; ------------------------------------------------------------------------------------------
; This is the config path of application.
; This is the config path of the application.
path = /etc/alignak_app

; # Path images
; ------------------------------------------------------------------------------------------
; Path of images. Must have a 'slash' before.
img = /images

; # States images
; Customize images
; You can customize your images if you want. They are all in svg and can be modify.
; But they had to be in [path] + [img] folder.

; # Icon
; ------------------------------------------------------------------------------------------
; This is the icon of alignak-app which is display in your notification area.
; Paste your custom image in "images" folder if you want to change.
icon = alignak.svg

; # Icon States
; ------------------------------------------------------------------------------------------
; Ths is the different colors of states.
ok = ok.svg
warning = warning.svg
alert = alert.svg

; # Host and Services States images
; ------------------------------------------------------------------------------------------
; You can customize your images if you want. But they have to keep in 'path' folder.
; This is all images of differents services and hosts states.
host_up = host_up.svg
host_down = host_down.svg
host_unreach = host_unreach.svg
Expand Down
58 changes: 37 additions & 21 deletions test/etc/settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

; # Frequency
; ------------------------------------------------------------------------------------------
; Defines (in seconds) the frequency of check of the backend API.
; Defines (in seconds) the frequency of check to the backend API.
; Default is 30
check_interval = 30

; # Get Notify
; # Notifications
; ------------------------------------------------------------------------------------------
; Choose if you want notify by popup or not
; Default is yes
; get_notify = yes
; Choose if you want to be notify by popup or not, when something change.
; If you set false, just the icon color change.
; If true, you get desktop notifications for each interval.
; Default is 'true'. Possible values are : 'true' or 'false'
notifications = true

[Backend]
; # Backend authentication
Expand All @@ -22,39 +24,53 @@ password = admin
; # Backend url
; ------------------------------------------------------------------------------------------
; The url of your Backend.
; Default is http://127.0.0.1:5000
; backend_url = http://127.0.0.1:5000
backend_url = http://94.76.229.155:90

[Webui]
; # Webui
; ------------------------------------------------------------------------------------------
; The url of your Webui
; Default is http://127.0.0.1:5001
; webui_url = http://127.0.0.1:5001
webui_url = http://94.76.229.155:91

[Config]
; # Icon
; ------------------------------------------------------------------------------------------
; This is the icon of alignak-app which is display in your notification area.
; Paste your custom image in "images" folder if you want to change.
icon = alignak.svg
ok = ok.svg
warning = warning.svg
alert = alert.svg

; # Config Path
; ------------------------------------------------------------------------------------------
; This is the config path of application.
; This is the config path of the application.
path = /etc/alignak_app

; # Path images
; ------------------------------------------------------------------------------------------
; Path of images. Must have a 'slash' before.
img = /images

; # States images
; Customize images
; You can customize your images if you want. They are all in svg and can be modify.
; But they had to be in [path] + [img] folder.

; # Icon
; ------------------------------------------------------------------------------------------
; This is the icon of alignak-app which is display in your notification area.
; Paste your custom image in "images" folder if you want to change.
icon = alignak.svg

; # Icon States
; ------------------------------------------------------------------------------------------
; Ths is the different colors of states.
ok = ok.svg
warning = warning.svg
alert = alert.svg

; # Host and Services States images
; ------------------------------------------------------------------------------------------
; You can customize your images if you want. But they have to keep in 'path' folder.
; This is all images of differents services and hosts states.
host_up = host_up.svg
host_down = host_down.png
service_up = host_up.png
service_down = host_down.png
service_unknown = service_unknown.png
host_down = host_down.svg
host_unreach = host_unreach.svg
service_ok = service_ok.svg
service_critical = service_critical.svg
service_unknown = service_unknown.svg
service_warning = service_warning.svg

0 comments on commit bff888e

Please sign in to comment.