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 if opmon_type == "stream" and "monkafka" not in path:
210 msg = "OpMon 'stream' configuration must publish to kafka, exiting."
211 raise ValueError(msg) from None
212 if opmon_type != "stream" and "monkafka" in path:
213 msg = "To use kafka, the type must be set to stream."
214 raise ValueError(msg) from None
215
216 bootstrap = None
217 topic = None
218 if opmon_type == "file" and not Path(path).parent.is_dir():
219 err_str = "Requested directory to put file in does not exist."
220 raise ValueError(err_str) from None
221 if "monkafka" in path:
222 bootstrap, topic = path.split("/", 1)
223 if not topic:
224 topic = "opmon_stream"
225 log.debug("Using OpMon topic: [green]'%s'[/green]", topic)
226 log.debug("Using OpMon bootstrap: [green]'%s'[/green]", bootstrap)
227
228 level = (
229 conf.get("level") if isinstance(conf, dict) else getattr(conf, "level", None)
230 )
231 if level:
232 log.debug("Found OpMon level: [green]%s[/green]", level)
233 else:
234 log.debug(
235 "Missing 'level' in the OpMon configuration, [yellow]using default "
236 "'DEBUG'[/yellow]."
237 )
238 level = logging.DEBUG
239
240 interval_s = (
241 conf.get("interval_s")
242 if isinstance(conf, dict)
243 else getattr(conf, "interval_s", None)
244 )
245 if interval_s:
246 log.debug("Found OpMon interval_s: %s", interval_s)
247 else:
248 log.debug(
249 "Missing 'interval_s' in the opmon configuration, [yellow]using default "
250 "10s[/yellow]."
251 )
252 interval_s = 10.0
253
254 return OpMonConf(
255 opmon_type, bootstrap, topic, level, interval_s, path, session, application
256 )
257
258