| 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 |
# Global variables used in different modules |
| 19 |
|
| 20 |
from dataclasses import dataclass |
| 21 |
|
| 22 |
from Nagstamon.config import (conf, |
| 23 |
OS, |
| 24 |
OS_MACOS, |
| 25 |
RESOURCES) |
| 26 |
from Nagstamon.helpers import FilesDict |
| 27 |
from Nagstamon.qui.dbus import DBus |
| 28 |
from Nagstamon.qui.qt import QFont |
| 29 |
from Nagstamon.qui.widgets.app import app |
| 30 |
|
| 31 |
|
| 32 |
# save default font to be able to reset to it |
| 33 |
font_default = app.font() |
| 34 |
|
| 35 |
# take global font from conf if it exists |
| 36 |
if conf.font != '': |
| 37 |
font = QFont() |
| 38 |
font.fromString(conf.font) |
| 39 |
else: |
| 40 |
font = font_default |
| 41 |
|
| 42 |
# always stay in normal weight without any italic |
| 43 |
font_icons = QFont('Nagstamon', font.pointSize() + 2, QFont.Weight.Normal, False) |
| 44 |
|
| 45 |
# DBus initialization |
| 46 |
dbus_connection = DBus() |
| 47 |
|
| 48 |
# check ECP authentication support availability |
| 49 |
try: |
| 50 |
from requests_ecp import HTTPECPAuth |
| 51 |
ecp_available = True |
| 52 |
except ImportError: |
| 53 |
ecp_available = False |
| 54 |
|
| 55 |
# flag to keep track of Kerberos availability |
| 56 |
kerberos_available = False |
| 57 |
if OS == OS_MACOS: |
| 58 |
# requests_gssapi is newer but not available everywhere |
| 59 |
try: |
| 60 |
# extra imports needed to get it compiled on macOS |
| 61 |
import numbers |
| 62 |
import gssapi.raw.cython_converters |
| 63 |
from requests_gssapi import HTTPSPNEGOAuth as HTTPSKerberos |
| 64 |
kerberos_available = True |
| 65 |
except ImportError as error: |
| 66 |
print(error) |
| 67 |
else: |
| 68 |
# requests_gssapi is newer but not available everywhere |
| 69 |
try: |
| 70 |
# requests_gssapi needs installation of KfW - Kerberos for Windows |
| 71 |
# requests_kerberoes doesn't |
| 72 |
from requests_kerberos import HTTPKerberosAuth as HTTPSKerberos |
| 73 |
kerberos_available = True |
| 74 |
except ImportError as error: |
| 75 |
print(error) |
| 76 |
|
| 77 |
|
| 78 |
@dataclass |
| 79 |
class StatusWindowProperties: |
| 80 |
""" |
| 81 |
storing statuswindow related variables globally available for several classes |
| 82 |
""" |
| 83 |
icon_x: int = 0 |
| 84 |
icon_y: int = 0 |
| 85 |
is_shown: bool = False |
| 86 |
is_shown_timestamp: float = 0.0 |
| 87 |
is_hiding_timestamp: float = 0.0 |
| 88 |
moving: bool = False |
| 89 |
relative_x: int = 0 |
| 90 |
relative_y: int = 0 |
| 91 |
status_ok: bool = True |
| 92 |
top: bool = False |
| 93 |
# flag about current notification state |
| 94 |
is_notifying: bool = False |
| 95 |
# current worst state worth a notification |
| 96 |
worst_notification_status: str = 'UP' |
| 97 |
notifying_server: str = '' |
| 98 |
debug_loop_looping = False |
| 99 |
|
| 100 |
# shared status window properties |
| 101 |
statuswindow_properties = StatusWindowProperties() |
| 102 |
|
| 103 |
# access to clipboard |
| 104 |
clipboard = app.clipboard() |
| 105 |
|
| 106 |
# QBrushes made of QColors for treeview model data() method |
| 107 |
# 2 flavours for alternating backgrounds |
| 108 |
# filled by create_brushes() |
| 109 |
qbrushes = {0: {}, 1: {}} |
| 110 |
|
| 111 |
# store default sounds as buffers to avoid https://github.com/HenriWahl/Nagstamon/issues/578 |
| 112 |
# meanwhile used as backup copy in case they had been deleted by macOS |
| 113 |
# https://github.com/HenriWahl/Nagstamon/issues/578 |
| 114 |
resource_files = FilesDict(RESOURCES) |