Debian Codegraph @

Nagstamon/qui/dialogs/submit.py

raw
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 DialogSubmit(Dialog):
25 """
26 dialog for submitting arbitrarily chosen results
27 """
28 # store host and service to be used for OK button evaluation
29 server = None
30 host = service = ''
31
32 submit = Signal(dict)
33
34 def __init__(self):
35 Dialog.__init__(self, 'dialog_submit')
36
37 @Slot(object, str, str)
38 def initialize(self, server=None, host='', service=''):
39 # store server, host and service to be used for OK button evaluation
40 self.server = server
41 self.host = host
42 self.service = service
43
44 # if service is "" it must be a host
45 if service == "":
46 # set label for acknowledging a host
47 self.window.setWindowTitle('Submit check result for host')
48 self.window.input_label_description.setText('Host <b>%s</b>' % (host))
49 # services do not need all states
50 self.window.input_radiobutton_result_up.show()
51 self.window.input_radiobutton_result_ok.hide()
52 self.window.input_radiobutton_result_warning.hide()
53 self.window.input_radiobutton_result_critical.hide()
54 self.window.input_radiobutton_result_unknown.show()
55 self.window.input_radiobutton_result_unreachable.show()
56 self.window.input_radiobutton_result_down.show()
57 # activate first radiobutton
58 self.window.input_radiobutton_result_up.setChecked(True)
59 else:
60 # set label for acknowledging a service on host
61 self.window.setWindowTitle('Submit check result for service')
62 self.window.input_label_description.setText('Service <b>%s</b> on host <b>%s</b>' % (service, host))
63 # hosts do not need all states
64 self.window.input_radiobutton_result_up.hide()
65 self.window.input_radiobutton_result_ok.show()
66 self.window.input_radiobutton_result_warning.show()
67 self.window.input_radiobutton_result_critical.show()
68 self.window.input_radiobutton_result_unknown.show()
69 self.window.input_radiobutton_result_unreachable.hide()
70 self.window.input_radiobutton_result_down.hide()
71 # activate first radiobutton
72 self.window.input_radiobutton_result_ok.setChecked(True)
73
74 # clear text fields
75 self.window.input_lineedit_check_output.setText('')
76 self.window.input_lineedit_performance_data.setText('')
77 self.window.input_lineedit_comment.setText(conf.defaults_submit_check_result_comment)
78 self.window.input_lineedit_check_output.setFocus()
79
80 def ok(self):
81 """
82 submit an arbitrary check result
83 """
84 # default state
85 state = "ok"
86
87 for button in ["ok", "up", "warning", "critical", "unreachable", "unknown", "down"]:
88 if self.window.__dict__['input_radiobutton_result_' + button].isChecked():
89 state = button
90 break
91
92 # tell worker to submit
93 self.submit.emit({'server': self.server,
94 'host': self.host,
95 'service': self.service,
96 'state': state,
97 'comment': self.window.input_lineedit_comment.text(),
98 'check_output': self.window.input_lineedit_check_output.text(),
99 'performance_data': self.window.input_lineedit_performance_data.text()})
100 # call close and macOS dock icon treatment from ancestor
101 super().ok()