2121@register_daemon_form
2222class SNMPGateway (ContainerDaemonForm ):
2323 """Defines an SNMP gateway between Prometheus and SNMP monitoring Frameworks"""
24+
2425 daemon_type = 'snmp-gateway'
2526 SUPPORTED_VERSIONS = ['V2c' , 'V3' ]
2627 default_image = DEFAULT_SNMP_GATEWAY_IMAGE
@@ -31,12 +32,14 @@ class SNMPGateway(ContainerDaemonForm):
3132 def for_daemon_type (cls , daemon_type : str ) -> bool :
3233 return cls .daemon_type == daemon_type
3334
34- def __init__ (self ,
35- ctx : CephadmContext ,
36- fsid : str ,
37- daemon_id : Union [int , str ],
38- config_json : Dict [str , Any ],
39- image : Optional [str ] = None ) -> None :
35+ def __init__ (
36+ self ,
37+ ctx : CephadmContext ,
38+ fsid : str ,
39+ daemon_id : Union [int , str ],
40+ config_json : Dict [str , Any ],
41+ image : Optional [str ] = None ,
42+ ) -> None :
4043 self .ctx = ctx
4144 self .fsid = fsid
4245 self .daemon_id = daemon_id
@@ -49,34 +52,51 @@ def __init__(self,
4952 self .snmp_version = config_json .get ('snmp_version' , 'V2c' )
5053 self .snmp_community = config_json .get ('snmp_community' , 'public' )
5154 self .log_level = config_json .get ('log_level' , 'info' )
52- self .snmp_v3_auth_username = config_json .get ('snmp_v3_auth_username' , '' )
53- self .snmp_v3_auth_password = config_json .get ('snmp_v3_auth_password' , '' )
54- self .snmp_v3_auth_protocol = config_json .get ('snmp_v3_auth_protocol' , '' )
55- self .snmp_v3_priv_protocol = config_json .get ('snmp_v3_priv_protocol' , '' )
56- self .snmp_v3_priv_password = config_json .get ('snmp_v3_priv_password' , '' )
55+ self .snmp_v3_auth_username = config_json .get (
56+ 'snmp_v3_auth_username' , ''
57+ )
58+ self .snmp_v3_auth_password = config_json .get (
59+ 'snmp_v3_auth_password' , ''
60+ )
61+ self .snmp_v3_auth_protocol = config_json .get (
62+ 'snmp_v3_auth_protocol' , ''
63+ )
64+ self .snmp_v3_priv_protocol = config_json .get (
65+ 'snmp_v3_priv_protocol' , ''
66+ )
67+ self .snmp_v3_priv_password = config_json .get (
68+ 'snmp_v3_priv_password' , ''
69+ )
5770 self .snmp_v3_engine_id = config_json .get ('snmp_v3_engine_id' , '' )
5871
5972 self .validate ()
6073
6174 @classmethod
62- def init (cls , ctx : CephadmContext , fsid : str ,
63- daemon_id : Union [int , str ]) -> 'SNMPGateway' :
75+ def init (
76+ cls , ctx : CephadmContext , fsid : str , daemon_id : Union [int , str ]
77+ ) -> 'SNMPGateway' :
6478 cfgs = fetch_configs (ctx )
6579 assert cfgs # assert some config data was found
6680 return cls (ctx , fsid , daemon_id , cfgs , ctx .image )
6781
6882 @classmethod
69- def create (cls , ctx : CephadmContext , ident : DaemonIdentity ) -> 'SNMPGateway' :
83+ def create (
84+ cls , ctx : CephadmContext , ident : DaemonIdentity
85+ ) -> 'SNMPGateway' :
7086 return cls .init (ctx , ident .fsid , ident .daemon_id )
7187
7288 @property
7389 def identity (self ) -> DaemonIdentity :
7490 return DaemonIdentity (self .fsid , self .daemon_type , self .daemon_id )
7591
7692 @staticmethod
77- def get_version (ctx : CephadmContext , fsid : str , daemon_id : str ) -> Optional [str ]:
93+ def get_version (
94+ ctx : CephadmContext , fsid : str , daemon_id : str
95+ ) -> Optional [str ]:
7896 """Return the version of the notifier from it's http endpoint"""
79- path = os .path .join (ctx .data_dir , fsid , f'snmp-gateway.{ daemon_id } ' , 'unit.meta' )
97+ path = os .path .join (
98+ ctx .data_dir , fsid , f'snmp-gateway.{ daemon_id } ' , 'unit.meta'
99+ )
80100 try :
81101 with open (path , 'r' ) as env :
82102 metadata = json .loads (env .read ())
@@ -95,8 +115,9 @@ def get_version(ctx: CephadmContext, fsid: str, daemon_id: str) -> Optional[str]
95115
96116 for h in html :
97117 stripped = h .strip ()
98- if stripped .startswith (('<pre>' , '<PRE>' )) and \
99- stripped .endswith (('</pre>' , '</PRE>' )):
118+ if stripped .startswith (('<pre>' , '<PRE>' )) and stripped .endswith (
119+ ('</pre>' , '</PRE>' )
120+ ):
100121 # <pre>(version=1.2.1, branch=HEAD, revision=7...
101122 return stripped .split (',' )[0 ].split ('version=' )[1 ]
102123
@@ -116,28 +137,36 @@ def get_daemon_args(self) -> List[str]:
116137 f'--snmp.destination={ self .destination } ' ,
117138 f'--snmp.version={ self .snmp_version } ' ,
118139 f'--log.level={ self .log_level } ' ,
119- '--snmp.trap-description-template=/etc/snmp_notifier/description-template.tpl'
140+ '--snmp.trap-description-template=/etc/snmp_notifier/description-template.tpl' ,
120141 ]
121142
122143 if self .snmp_version == 'V3' :
123144 # common auth settings
124- v3_args .extend ([
125- '--snmp.authentication-enabled' ,
126- f'--snmp.authentication-protocol={ self .snmp_v3_auth_protocol } ' ,
127- f'--snmp.security-engine-id={ self .snmp_v3_engine_id } '
128- ])
145+ v3_args .extend (
146+ [
147+ '--snmp.authentication-enabled' ,
148+ f'--snmp.authentication-protocol={ self .snmp_v3_auth_protocol } ' ,
149+ f'--snmp.security-engine-id={ self .snmp_v3_engine_id } ' ,
150+ ]
151+ )
129152 # authPriv setting is applied if we have a privacy protocol setting
130153 if self .snmp_v3_priv_protocol :
131- v3_args .extend ([
132- '--snmp.private-enabled' ,
133- f'--snmp.private-protocol={ self .snmp_v3_priv_protocol } '
134- ])
154+ v3_args .extend (
155+ [
156+ '--snmp.private-enabled' ,
157+ f'--snmp.private-protocol={ self .snmp_v3_priv_protocol } ' ,
158+ ]
159+ )
135160
136161 return base_args + v3_args
137162
138163 @property
139164 def data_dir (self ) -> str :
140- return os .path .join (self .ctx .data_dir , self .ctx .fsid , f'{ self .daemon_type } .{ self .daemon_id } ' )
165+ return os .path .join (
166+ self .ctx .data_dir ,
167+ self .ctx .fsid ,
168+ f'{ self .daemon_type } .{ self .daemon_id } ' ,
169+ )
141170
142171 @property
143172 def conf_file_path (self ) -> str :
@@ -149,10 +178,16 @@ def create_daemon_conf(self) -> None:
149178 if self .snmp_version == 'V2c' :
150179 f .write (f'SNMP_NOTIFIER_COMMUNITY={ self .snmp_community } \n ' )
151180 else :
152- f .write (f'SNMP_NOTIFIER_AUTH_USERNAME={ self .snmp_v3_auth_username } \n ' )
153- f .write (f'SNMP_NOTIFIER_AUTH_PASSWORD={ self .snmp_v3_auth_password } \n ' )
181+ f .write (
182+ f'SNMP_NOTIFIER_AUTH_USERNAME={ self .snmp_v3_auth_username } \n '
183+ )
184+ f .write (
185+ f'SNMP_NOTIFIER_AUTH_PASSWORD={ self .snmp_v3_auth_password } \n '
186+ )
154187 if self .snmp_v3_priv_password :
155- f .write (f'SNMP_NOTIFIER_PRIV_PASSWORD={ self .snmp_v3_priv_password } \n ' )
188+ f .write (
189+ f'SNMP_NOTIFIER_PRIV_PASSWORD={ self .snmp_v3_priv_password } \n '
190+ )
156191
157192 def validate (self ) -> None :
158193 """Validate the settings
@@ -169,7 +204,9 @@ def validate(self) -> None:
169204 raise Error (f'not a valid snmp version: { self .snmp_version } ' )
170205
171206 if not self .destination :
172- raise Error ('config is missing destination attribute(<ip>:<port>) of the target SNMP listener' )
207+ raise Error (
208+ 'config is missing destination attribute(<ip>:<port>) of the target SNMP listener'
209+ )
173210
174211 def container (self , ctx : CephadmContext ) -> CephContainer :
175212 ctr = daemon_to_container (ctx , self )
0 commit comments