| 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 |
from Nagstamon.config import conf |
| 19 |
from Nagstamon.qui.dialogs.dialog import Dialog |
| 20 |
from Nagstamon.qui.qt import (Signal, |
| 21 |
Slot) |
| 22 |
|
| 23 |
|
| 24 |
class DialogDowntime(Dialog): |
| 25 |
""" |
| 26 |
dialog for putting hosts/services into downtime |
| 27 |
""" |
| 28 |
|
| 29 |
# send signal to get start and end of downtime asynchronously |
| 30 |
get_start_end = Signal(str, str) |
| 31 |
|
| 32 |
# signal to tell worker to commit downtime |
| 33 |
downtime = Signal(dict) |
| 34 |
|
| 35 |
# store host and service to be used for OK button evaluation |
| 36 |
server = None |
| 37 |
host_list = service_list = [] |
| 38 |
|
| 39 |
def __init__(self): |
| 40 |
Dialog.__init__(self, 'dialog_downtime') |
| 41 |
|
| 42 |
def initialize(self, server=None, host=[], service=[]): |
| 43 |
# store server, host and service to be used for OK button evaluation |
| 44 |
self.server = server |
| 45 |
self.host_list = host |
| 46 |
self.service_list = service |
| 47 |
|
| 48 |
self.window.setWindowTitle('Downtime for host and service') |
| 49 |
text = '' |
| 50 |
|
| 51 |
for i in range(len(self.host_list)): |
| 52 |
if self.service_list[i] == "": |
| 53 |
text += f'Host <b>{self.host_list[i]}</b><br>' |
| 54 |
else: |
| 55 |
text += f'Service <b>{self.service_list[i]}</b> on host <b>{self.host_list[i]}</b><br>' |
| 56 |
|
| 57 |
self.window.input_label_description.setText(text) |
| 58 |
|
| 59 |
# default flags of monitor acknowledgement |
| 60 |
self.window.input_spinbox_duration_hours.setValue(int(conf.defaults_downtime_duration_hours)) |
| 61 |
self.window.input_spinbox_duration_minutes.setValue(int(conf.defaults_downtime_duration_minutes)) |
| 62 |
self.window.input_radiobutton_type_fixed.setChecked(conf.defaults_downtime_type_fixed) |
| 63 |
self.window.input_radiobutton_type_flexible.setChecked(conf.defaults_downtime_type_flexible) |
| 64 |
|
| 65 |
# hide/show downtime settings according to type |
| 66 |
self.window.input_radiobutton_type_fixed.clicked.connect(self.set_type_fixed) |
| 67 |
self.window.input_radiobutton_type_flexible.clicked.connect(self.set_type_flexible) |
| 68 |
|
| 69 |
# show or hide widgets for time settings |
| 70 |
if self.window.input_radiobutton_type_fixed.isChecked(): |
| 71 |
self.set_type_fixed() |
| 72 |
else: |
| 73 |
self.set_type_flexible() |
| 74 |
|
| 75 |
# empty times at start, will be filled by set_start_end |
| 76 |
self.window.input_lineedit_start_time.setText('n/a') |
| 77 |
self.window.input_lineedit_end_time.setText('n/a') |
| 78 |
|
| 79 |
# default author + comment |
| 80 |
self.window.input_lineedit_comment.setText(conf.defaults_downtime_comment) |
| 81 |
self.window.input_lineedit_comment.setFocus() |
| 82 |
|
| 83 |
if self.server is not None: |
| 84 |
# at first initialization server is still None |
| 85 |
self.get_start_end.emit(self.server.name, self.host_list[0]) |
| 86 |
|
| 87 |
def ok(self): |
| 88 |
""" |
| 89 |
schedule downtime for miserable host/service |
| 90 |
""" |
| 91 |
# type of downtime - fixed or flexible |
| 92 |
if self.window.input_radiobutton_type_fixed.isChecked() is True: |
| 93 |
fixed = 1 |
| 94 |
else: |
| 95 |
fixed = 0 |
| 96 |
|
| 97 |
for line_number in range(len(self.host_list)): |
| 98 |
service = self.service_list[line_number] |
| 99 |
host = self.host_list[line_number] |
| 100 |
|
| 101 |
self.downtime.emit({'server': self.server, |
| 102 |
'host': host, |
| 103 |
'service': service, |
| 104 |
'author': self.server.username, |
| 105 |
'comment': self.window.input_lineedit_comment.text(), |
| 106 |
'fixed': fixed, |
| 107 |
'start_time': self.window.input_lineedit_start_time.text(), |
| 108 |
'end_time': self.window.input_lineedit_end_time.text(), |
| 109 |
'hours': int(self.window.input_spinbox_duration_hours.value()), |
| 110 |
'minutes': int(self.window.input_spinbox_duration_minutes.value())}) |
| 111 |
# call close and macOS dock icon treatment from ancestor |
| 112 |
super().ok() |
| 113 |
|
| 114 |
@Slot(str, str) |
| 115 |
def set_start_end(self, start, end): |
| 116 |
""" |
| 117 |
put values sent by worker into start and end fields |
| 118 |
""" |
| 119 |
self.window.input_lineedit_start_time.setText(start) |
| 120 |
self.window.input_lineedit_end_time.setText(end) |
| 121 |
|
| 122 |
@Slot() |
| 123 |
def set_type_fixed(self): |
| 124 |
""" |
| 125 |
enable/disable appropriate widgets if type is "Fixed" |
| 126 |
""" |
| 127 |
self.window.label_duration.hide() |
| 128 |
self.window.label_duration_hours.hide() |
| 129 |
self.window.label_duration_minutes.hide() |
| 130 |
self.window.input_spinbox_duration_hours.hide() |
| 131 |
self.window.input_spinbox_duration_minutes.hide() |
| 132 |
|
| 133 |
@Slot() |
| 134 |
def set_type_flexible(self): |
| 135 |
""" |
| 136 |
enable/disable appropriate widgets if type is "Flexible" |
| 137 |
""" |
| 138 |
self.window.label_duration.show() |
| 139 |
self.window.label_duration_hours.show() |
| 140 |
self.window.label_duration_minutes.show() |
| 141 |
self.window.input_spinbox_duration_hours.show() |
| 142 |
self.window.input_spinbox_duration_minutes.show() |