Oi dZddlmZddlZddlZddlmZmZmZddlm Z ddl m Z e e jjjZedz Zedz Zed z Zed z Zd Zed ZefddZddZddZefddZy)z3Logbook anomaly detection for Sentinel diagnostics.) annotationsN)datetime timedeltatimezone)Path)Anylogbookzcollect_logs.pyreportsz latest.txtP$)hoursctjs ddtfS tjtj t tdt |gdddd}|jd k7rR|jj}|jj}|xs|xsd |j}dd |fSy #t$rYytj$rYywxYw) z:Invoke the logbook collector to refresh the latest report.Fzlogbook script missing: z--linesT<)capture_outputtextchecktimeout)Fz3python interpreter not found to run collect_logs.py)Fzcollect_logs.py timed outrz exit status zcollect_logs.py failed: )TN) COLLECT_SCRIPTexists subprocessrunsys executablestrFileNotFoundErrorTimeoutExpired returncodestderrstripstdout) max_linesresultrr messages 4/mnt/ssd/adrian/flotta-diagnostics/logbook_health.py_refresh_reportr%s  "00@AAA 2 ^^S0)S^ L  A$$&$$&HFH V5F5F4G&H0 :::  LK  $ $212sAC C%C%$C%ctjs ddtfS tjddfS#t$r}ddtd|fcYd}~Sd}~wwxYw)z$Load the most recent logbook report.Nzlogbook report missing: zutf-8)encodingzunable to read z: ) LATEST_REPORTr read_textOSError)excs r$_read_latest_reportr,0sg    !/ ???>&&&8$>> >}oRu===>s9 A AAAcd}d}g}tjjj}|j D]}|j }|s|z|j dri|jdd}t|dk(rG|dj } tj|}|j|j|}||j ds|j d s|}|j drT|jd \} } } | r=| jd D cgc]#} | j s| j %}} n|||d S#t$rd}YwxYwcc} w) z/Parse the logbook report for status indicators.Nz# Logbook reportu–)maxsplit)tzinfou⚠️u✅:,) generated_at status_lineissues) rnow astimezoner1 splitlinesr startswithsplitlen fromisoformatreplace ValueError partition) report_textr4r5r6local_tzraw_linelineparts timestamp_str_ remainderchunks r$_extract_metadatarJ;ss$(L"KF||~((*11H**,~~   DOO4F$GJJuqJ1E5zQ %a 0 (#+#9#9-#HL#**2'3';';8';'L    DOOH$=QVAWKx("&.."51i9B9M_QVQ\Q\Q^ekkm_F_ 16%" "(#'L(`s"3E,9E=E=, E:9E:cBt|\}}|sd|dSt\}}|d|dSt|}|d}tjt j }tt|dd}|rm|j|d<||jt j z } | tkDrHd|d<d | jd z d d |d <|dr|d|d<|Sd|d<d|d <|dr|d|d<|St|d} | rdnd|d<|dr|d|d<|S)z:Return the latest logbook status for Sentinel diagnostics.)r!ERROR)statuserrorr4r6) report_pathr6STALErMzlogbook report is iz.1fz hours oldrNr5WARNz8unable to parse generation timestamp from logbook reportALERTOK)r%r,rJrr7rutcrr( isoformatr8STALE_THRESHOLD total_secondsbool) r! refreshedrNrA read_errormetadatar4r7payloadage has_issuess r$ check_logbookr_dsi&;Iu !E2213K!J77 -HN+L ,,x|| $C=)8$G "."8"8":L++HLL99  'GH !3C4E4E4G$4Ns3SS]^GG  &)1-)@ &N"U M "%-m%rps9" 22 > ! ! # * * 1 1" 00I% l* "%&76>&R$5(r`