33# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
44# conditions defined in the file COPYING, which is part of this source code package.
55
6+ from collections .abc import Mapping
7+ from typing import Any
8+
69from cmk .gui .config import Config
710from cmk .gui .htmllib .foldable_container import foldable_container
811from cmk .gui .htmllib .html import html
912from cmk .gui .http import request
1013from cmk .gui .i18n import _
11- from cmk .gui .sidebar ._snapin ._base import SidebarSnapin
12- from cmk .gui .sidebar ._snapin ._helpers import footnotelinks
14+ from cmk .gui .sidebar import footnotelinks , PageHandlers , SidebarSnapin
1315
1416
1517class NagVisMaps (SidebarSnapin ):
1618 @staticmethod
17- def type_name ():
19+ def type_name () -> str :
1820 return "nagvis_maps"
1921
2022 @classmethod
21- def title (cls ):
23+ def title (cls ) -> str :
2224 return _ ("NagVis maps" )
2325
2426 @classmethod
25- def description (cls ):
27+ def description (cls ) -> str :
2628 return _ ("List of available NagVis maps" )
2729
2830 @classmethod
29- def refresh_regularly (cls ):
31+ def refresh_regularly (cls ) -> bool :
3032 return False
3133
3234 def show (self , config : Config ) -> None :
3335 html .div (_ ("Loading maps..." ), class_ = "loading" )
3436 html .javascript ("cmk.sidebar.fetch_nagvis_snapin_contents()" )
3537
36- def page_handlers (self ):
38+ def page_handlers (self ) -> PageHandlers :
3739 return {
3840 "ajax_nagvis_maps_snapin" : self ._ajax_show_nagvis_maps_snapin ,
3941 }
4042
41- def _ajax_show_nagvis_maps_snapin (self ):
43+ def _ajax_show_nagvis_maps_snapin (self ) -> None :
4244 api_request = request .get_request ()
4345 if api_request ["type" ] == "table" :
4446 self ._show_table (api_request )
@@ -51,7 +53,7 @@ def _ajax_show_nagvis_maps_snapin(self):
5153
5254 self ._show_footnote_links ()
5355
54- def _show_table (self , api_request ) :
56+ def _show_table (self , api_request : Mapping [ str , Any ]) -> None :
5557 html .open_table (class_ = "allhosts" )
5658 html .open_tbody ()
5759
@@ -63,9 +65,9 @@ def _show_table(self, api_request):
6365 class_ = [
6466 "statebullet" ,
6567 self ._state_class (map_cfg ),
66- self . _sub_state_class ( map_cfg ),
67- self ._stale_class (map_cfg ),
68- ] ,
68+ ]
69+ + self ._sub_state_class (map_cfg )
70+ + self . _stale_class ( map_cfg ) ,
6971 title = self ._state_title (map_cfg ),
7072 )
7173 html .a (map_cfg ["alias" ], href = map_cfg ["url" ], class_ = "link" , target = "main" )
@@ -75,7 +77,7 @@ def _show_table(self, api_request):
7577 html .close_tbody ()
7678 html .close_table ()
7779
78- def _state_class (self , map_cfg ) :
80+ def _state_class (self , map_cfg : Mapping [ str , Any ]) -> str :
7981 return {
8082 "OK" : "state0" ,
8183 "UP" : "state0" ,
@@ -86,19 +88,19 @@ def _state_class(self, map_cfg):
8688 "PENDING" : "statep" ,
8789 }.get (map_cfg ["summary_state" ], "state3" )
8890
89- def _sub_state_class (self , map_cfg ) :
91+ def _sub_state_class (self , map_cfg : Mapping [ str , Any ]) -> list [ str ] :
9092 if map_cfg ["summary_in_downtime" ]:
91- return "stated"
93+ return [ "stated" ]
9294 if map_cfg ["summary_problem_has_been_acknowledged" ]:
93- return "statea"
94- return None
95+ return [ "statea" ]
96+ return []
9597
96- def _stale_class (self , map_cfg ) :
98+ def _stale_class (self , map_cfg : Mapping [ str , Any ]) -> list [ str ] :
9799 if map_cfg ["summary_stale" ]:
98- return "stale"
99- return None
100+ return [ "stale" ]
101+ return []
100102
101- def _state_title (self , map_cfg ) :
103+ def _state_title (self , map_cfg : Mapping [ str , Any ]) -> str :
102104 title = map_cfg ["summary_state" ]
103105
104106 if map_cfg ["summary_in_downtime" ]:
@@ -115,16 +117,20 @@ def _state_title(self, map_cfg):
115117
116118 return title
117119
118- def _show_footnote_links (self ):
120+ def _show_footnote_links (self ) -> None :
119121 edit_url = "../nagvis/"
120122 footnotelinks ([(_ ("Edit" ), edit_url )])
121123
122- def _show_tree (self , api_request ) :
124+ def _show_tree (self , api_request : Mapping [ str , Any ]) -> None :
123125 html .open_ul ()
124126 self ._show_tree_nodes (api_request ["maps" ]["maps" ], api_request ["maps" ]["childs" ])
125127 html .close_ul ()
126128
127- def _show_tree_nodes (self , maps , children ):
129+ def _show_tree_nodes (
130+ self ,
131+ maps : Mapping [str , Mapping [str , Any ]],
132+ children : Mapping [str , Mapping [str , Mapping [str , Any ]]],
133+ ) -> None :
128134 for map_name , map_cfg in maps .items ():
129135 html .open_li ()
130136 if map_name in children :
0 commit comments