177) -> dict[str:str]:
178 """Parse the OpMonConf and OpMonURI."""
179 if not conf:
180 log.error("Missing opmon configuration, exiting.")
181 sys.exit(1)
182 if not uri:
183 log.error("Missing opmon URI, exiting.")
184 sys.exit(1)
185
186 opmon_type = (
187 uri.get("type") if isinstance(uri, dict) else getattr(uri, "type", None)
188 )
189 if opmon_type:
190 log.debug("Found OpMon type: %s", opmon_type)
191 else:
192 log.debug(
193 "Missing 'type' in the opmon configuration, [yellow]using default value "
194 "'stdout'[/yellow]."
195 )
196 opmon_type = "stdout"
197
198 path = uri.get("path") if isinstance(uri, dict) else getattr(uri, "path", None)
199 if path:
200 log.debug("Found OpMon path: %s", path)
201 elif opmon_type != "stdout":
202 log.error("Missing 'path' in the opmon configuration, exiting.")
203 sys.exit(1)
204 else:
205 if path == []:
206 path = ""
207 log.debug("No OpMon path required for type 'stdout'.")
208
209 bootstrap = None
210 topic = None
211 if opmon_type == "file" and not Path(path).parent.is_dir():
212 err_str = "Requested directory to put file in does not exist."
213 raise ValueError(err_str) from None
214 if "monkafka" in path:
215 bootstrap, topic = path.split("/", 1)
216 if not topic:
217 topic = "opmon_stream"
218 log.debug("Using OpMon topic: [green]'%s'[/green]", topic)
219 log.debug("Using OpMon bootstrap: [green]'%s'[/green]", bootstrap)
220
221 level = (
222 conf.get("level") if isinstance(conf, dict) else getattr(conf, "level", None)
223 )
224 if level:
225 log.debug("Found OpMon level: [green]%s[/green]", level)
226 else:
227 log.debug(
228 "Missing 'level' in the OpMon configuration, [yellow]using default "
229 "'DEBUG'[/yellow]."
230 )
231 level = logging.DEBUG
232
233 interval_s = (
234 conf.get("interval_s")
235 if isinstance(conf, dict)
236 else getattr(conf, "interval_s", None)
237 )
238 if interval_s:
239 log.debug("Found OpMon interval_s: %s", interval_s)
240 else:
241 log.debug(
242 "Missing 'interval_s' in the opmon configuration, [yellow]using default "
243 "10s[/yellow]."
244 )
245 interval_s = 10.0
246
247 return OpMonConf(
248 opmon_type, bootstrap, topic, level, interval_s, path, session, application
249 )
250
251