| 1 |
# Nagstamon - Nagios status monitor for your desktop |
| 2 |
# Copyright (C) 2008-2026 Henri Wahl <[email protected]> et al. |
| 3 |
# |
| 4 |
# This program is free software; you can redistribute it and/or modify |
| 5 |
# it under the terms of the GNU General Public License as published by |
| 6 |
# the Free Software Foundation; either version 2 of the License, or |
| 7 |
# (at your option) any later version. |
| 8 |
# |
| 9 |
# This program is distributed in the hope that it will be useful, |
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
# GNU General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU General Public License |
| 15 |
# along with this program; if not, write to the Free Software |
| 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
| 17 |
|
| 18 |
|
| 19 |
from Nagstamon.config import conf |
| 20 |
from Nagstamon.qui.dialogs.dialog import Dialog |
| 21 |
from Nagstamon.qui.qt import (QDateTime, |
| 22 |
Signal, |
| 23 |
Slot) |
| 24 |
from Nagstamon.servers import SERVER_TYPES |
| 25 |
|
| 26 |
class DialogAcknowledge(Dialog): |
| 27 |
""" |
| 28 |
dialog for acknowledging host/service problems |
| 29 |
""" |
| 30 |
|
| 31 |
# store host and service to be used for OK button evaluation |
| 32 |
server = None |
| 33 |
host_list = service_list = [] |
| 34 |
|
| 35 |
# tell worker to acknowledge some troublesome item |
| 36 |
acknowledge = Signal(dict) |
| 37 |
|
| 38 |
def __init__(self,): |
| 39 |
Dialog.__init__(self, 'dialog_acknowledge') |
| 40 |
|
| 41 |
self.TOGGLE_DEPS = { |
| 42 |
self.window.input_checkbox_use_expire_time: [self.window.input_datetime_expire_time] |
| 43 |
} |
| 44 |
|
| 45 |
# still clumsy but better than negating the other server types |
| 46 |
PROMETHEUS_OR_ALERTMANAGER = ['Alertmanager', |
| 47 |
'Prometheus'] |
| 48 |
NOT_PROMETHEUS_OR_ALERTMANAGER = [x.TYPE for x in SERVER_TYPES.values() if |
| 49 |
x.TYPE not in PROMETHEUS_OR_ALERTMANAGER] |
| 50 |
|
| 51 |
self.VOLATILE_WIDGETS = { |
| 52 |
self.window.input_checkbox_use_expire_time: ['IcingaWeb2', 'Icinga2API', 'IcingaDBWeb'], |
| 53 |
self.window.input_datetime_expire_time: ['IcingaWeb2', 'Icinga2API', 'IcingaDBWeb', 'Alertmanager'], |
| 54 |
self.window.input_checkbox_sticky_acknowledgement: NOT_PROMETHEUS_OR_ALERTMANAGER, |
| 55 |
self.window.input_checkbox_send_notification: NOT_PROMETHEUS_OR_ALERTMANAGER, |
| 56 |
self.window.input_checkbox_persistent_comment: NOT_PROMETHEUS_OR_ALERTMANAGER, |
| 57 |
self.window.input_checkbox_acknowledge_all_services: NOT_PROMETHEUS_OR_ALERTMANAGER |
| 58 |
} |
| 59 |
|
| 60 |
self.FORCE_DATETIME_EXPIRE_TIME = ['Alertmanager'] |
| 61 |
|
| 62 |
@Slot(object, list, list) |
| 63 |
def initialize(self, server=None, host=[], service=[]): |
| 64 |
# store server, host and service to be used for OK button evaluation |
| 65 |
self.server = server |
| 66 |
self.host_list = host |
| 67 |
self.service_list = service |
| 68 |
|
| 69 |
self.window.setWindowTitle('Acknowledge hosts and services') |
| 70 |
text = '' |
| 71 |
|
| 72 |
for i in range(len(self.host_list)): |
| 73 |
if self.service_list[i] == "": |
| 74 |
text += f'Host <b>{self.host_list[i]}</b><br>' |
| 75 |
else: |
| 76 |
text += f'Service <b>{self.service_list[i]}</b> on host <b>{self.host_list[i]}</b><br>' |
| 77 |
|
| 78 |
self.window.input_label_description.setText(text) |
| 79 |
|
| 80 |
# default flags of monitor acknowledgement |
| 81 |
self.window.input_checkbox_sticky_acknowledgement.setChecked(conf.defaults_acknowledge_sticky) |
| 82 |
self.window.input_checkbox_send_notification.setChecked(conf.defaults_acknowledge_send_notification) |
| 83 |
self.window.input_checkbox_persistent_comment.setChecked(conf.defaults_acknowledge_persistent_comment) |
| 84 |
self.window.input_checkbox_use_expire_time.setChecked(conf.defaults_acknowledge_expire) |
| 85 |
if len(self.host_list) == 1: |
| 86 |
self.window.input_checkbox_acknowledge_all_services.setChecked(conf.defaults_acknowledge_all_services) |
| 87 |
self.window.input_checkbox_acknowledge_all_services.show() |
| 88 |
else: |
| 89 |
self.window.input_checkbox_acknowledge_all_services.setChecked(False) |
| 90 |
self.window.input_checkbox_acknowledge_all_services.hide() |
| 91 |
|
| 92 |
# default author + comment |
| 93 |
self.window.input_lineedit_comment.setText(conf.defaults_acknowledge_comment) |
| 94 |
self.window.input_lineedit_comment.setFocus() |
| 95 |
|
| 96 |
# set default and minimum value for expiry time |
| 97 |
qdatetime = QDateTime.currentDateTime() |
| 98 |
self.window.input_datetime_expire_time.setMinimumDateTime(qdatetime) |
| 99 |
# set default expiry time from configuration |
| 100 |
self.window.input_datetime_expire_time.setDateTime(qdatetime.addSecs( |
| 101 |
conf.defaults_acknowledge_expire_duration_hours * 60 * 60 + conf.defaults_acknowledge_expire_duration_minutes * 60 |
| 102 |
)) |
| 103 |
|
| 104 |
# Show or hide widgets based on server |
| 105 |
if self.server is not None: |
| 106 |
for widget, server_types in self.VOLATILE_WIDGETS.items(): |
| 107 |
if self.server.TYPE in server_types: |
| 108 |
widget.show() |
| 109 |
self.toggle_toggles() |
| 110 |
else: |
| 111 |
widget.hide() |
| 112 |
if self.server.TYPE in self.FORCE_DATETIME_EXPIRE_TIME: |
| 113 |
self.window.input_datetime_expire_time.show() |
| 114 |
|
| 115 |
# Adjust to current size if items are hidden in the menu |
| 116 |
# Otherwise it will get confused and chop off text |
| 117 |
self.window.options_groupbox.adjustSize() |
| 118 |
self.window.adjustSize() |
| 119 |
|
| 120 |
def ok(self): |
| 121 |
""" |
| 122 |
acknowledge miserable host/service |
| 123 |
""" |
| 124 |
# create a list of all service of selected host to acknowledge them all |
| 125 |
all_services = list() |
| 126 |
acknowledge_all_services = self.window.input_checkbox_acknowledge_all_services.isChecked() |
| 127 |
|
| 128 |
if acknowledge_all_services is True: |
| 129 |
for i in self.server.nagitems_filtered["services"].values(): |
| 130 |
for s in i: |
| 131 |
if s.host in self.host_list: |
| 132 |
all_services.append(s.name) |
| 133 |
|
| 134 |
if self.window.input_checkbox_use_expire_time.isChecked() or self.server.TYPE in self.FORCE_DATETIME_EXPIRE_TIME: |
| 135 |
# Format used in UI |
| 136 |
# 2019-11-01T18:17:39 |
| 137 |
expire_datetime = self.window.input_datetime_expire_time.dateTime().toString("yyyy-MM-ddTHH:mm:ss") |
| 138 |
else: |
| 139 |
expire_datetime = None |
| 140 |
|
| 141 |
for line_number in range(len(self.host_list)): |
| 142 |
service = self.service_list[line_number] |
| 143 |
host = self.host_list[line_number] |
| 144 |
|
| 145 |
# send signal to tablewidget worker to care about acknowledging with supplied information |
| 146 |
self.acknowledge.emit({'server': self.server, |
| 147 |
'host': host, |
| 148 |
'service': service, |
| 149 |
'author': self.server.username, |
| 150 |
'comment': self.window.input_lineedit_comment.text(), |
| 151 |
'sticky': self.window.input_checkbox_sticky_acknowledgement.isChecked(), |
| 152 |
'notify': self.window.input_checkbox_send_notification.isChecked(), |
| 153 |
'persistent': self.window.input_checkbox_persistent_comment.isChecked(), |
| 154 |
'acknowledge_all_services': acknowledge_all_services, |
| 155 |
'all_services': all_services, |
| 156 |
'expire_time': expire_datetime}) |
| 157 |
# call close and macOS dock icon treatment from ancestor |
| 158 |
super().ok() |