
    9Yf                         d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlmZm	Z	  ej                  d      Zd Zd Zd Zd Zd	 Z G d
 de      Zy)    N)api)report_errorsreport_warningsz)(?P<delta>[0-9]*\.?[0-9]+)(?P<unit>[mhd])c                 V   | d   xs d}| j                  dd      xs d}| j                  dd      xs d}| d   }t        j                  j                  |      }| d   }t        |dz   |z   dz   dz   |z   d	z   j	                                t        |j                  d      d
z   |z          y )Ntitle texthandledate_happenedurl z ()z | )getdatetimefromtimestampprintstrip	isoformat)eventr   r	   r
   datedtlinks          V/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/datadog/dogshell/event.pyprettyprint_eventr      s    'N bE99VR &BDYYx$*F!D				(	(	.B<D 
53;#d*V3c9
@
@
BC	",,s
e
#d
*+    c                     t        |        y Nr   r   s    r   print_eventr        
    er   c                     t        |        y r   r   r   s    r   prettyprint_event_detailsr#   $   r!   r   c                     t        |        y r   r   r   s    r   print_event_detailsr%   (   r!   r   c                    t        j                  t        j                  j                         j	                               }| |}t        |      S 	 t        |       }t        |      S # t        $ r t        j                  |       }|t        t        |j                  d            }|j                  d      }|dk(  r|dz  }|dk(  r|dz  dz  }|dk(  r|dz  dz  dz  }|t        |      z
  }Y t        |      S w xY w)Ndeltaunitm<   hd   )timemktimer   now	timetupleint	Exceptiontime_patmatchfloatgroup)
timestringr0   tr5   r'   r(   s         r   
parse_timer:   ,   s    
++h''++-779
:C" q6M	!JA q6M  	!NN:.E}%++g./E;;v&Ds{
s{
Rs{
R",c%j Aq6M	!s   A& &BC98C9c                   L    e Zd Zed        Zed        Zed        Zed        Zy)EventClientc                 `   |j                  dd      }|j                  dd      }d|_        |j                  dd	      }|j                  d
d       |j                  dt        d       |j                  dd       |j                  ddd       |j                  dd       |j                  dd       |j                  ddd       |j                  ddd       |j                  d d!       |j                  d"d#       |j                  d$d%       |j                  d&d'       |j                  d(d)d*+       |j                  | j                  ,       |j                  d-d.      }|j                  d/d0       |j                  | j                  ,       |j                  d1d2d34      }|j                  d5d6       |j                  d7d8d*+       |j                  dd9       |j                  d:d;       |j                  dd<       |j                  | j                  ,       y )=Nr   z:Post events, get event details, and view the event stream.)helpVerbsverb)r   destTpostzPost events.r   zevent titlez--date_happenedzOPOSIX timestamp when the event occurred. if unset defaults to the current time.)typer>   z--handlez;user to post as. if unset, submits as the generic API user.z
--priorityz'"normal" or "low". defaults to "normal"normal)r>   defaultz--related_event_idz>event to post as a child of. if unset, posts a top-level eventz--tagszcomma separated list of tagsz--hostz-related host (default to the local host name)r   z	--no_hostz8no host is associated with the event (overrides --host))
store_true)r>   actionz--devicez%related device (e.g. eth0, /dev/sda1)z--aggregation_keyzkey to aggregate the event withz--typez)type of event, e.g. nagios, jenkins, etc.z--alert_typez;"error", "warning", "info" or "success". defaults to "info"messagez/event message body. if unset, reads from stdin.?)r>   nargs)funcshowzShow event details.event_idzevent to showstreamz%Retrieve events from the Event StreamzStream start and end times can be specified as either a POSIX timestamp (e.g. the output of `date +%s`) or as a period of time in the past (e.g. '5m', '6h', '3d').)r>   descriptionstartz!start date for the stream requestendz3end date for the stream request (defaults to 'now')z;filter by priority. 'normal' or 'low'. defaults to 'normal'z	--sourcesz,comma separated list of sources to filter byz)comma separated list of tags to filter by)	
add_parseradd_subparsersrequiredadd_argumentr2   set_defaults_post_show_stream)cls
subparsersparserverb_parserspost_parsershow_parserstream_parsers          r   setup_parserzEventClient.setup_parserD   sc   &&w5t&u,,7,H $"--f>-J  } =  e 	! 	

 	  2r s  4]go p   'j 	! 	
 	  0N O  0_ik l  [dp 	! 	
 	  2Y Z  !4;\ ]  0[ \  6s t  1emp q  cii 0"--f;P-Q  / B  cii 0$//89 0 
 	""71T"U""5/gor"s""<6v"w"";5c"d""82]"^"""4r   c                 (   |j                   t        _        |j                  }|j                  }|t
        j                  j                         }|j                  7|j                  j                  d      D cg c]  }|j                          }}nd}|j                  rdn|j                  }t        j                  j                  |j                  ||j                   |j"                  |j$                  |j&                  |||j(                  |j*                  |j,                  |j.                        }t1        |       t3        |       |dk(  rt5        |d          y|dk(  rt7        t9        j:                  |             yt=        |d          yc c}w )z 
        Post an event.
        N,)r   r	   r   r
   priorityrelated_event_idtagshostdeviceaggregation_keysource_type_name
alert_typeprettyr   raw)timeoutr   _timeoutformatrH   sysstdinreadrf   splitr   no_hostrg   Eventcreater   r   r
   rd   re   rh   ri   rC   rk   r   r   r   r   jsondumpsr    )rZ   argsrp   rH   r9   rf   rg   ress           r   rW   zEventClient._postt   s3   
 ||,,?iinn&G99 '+yys';<!AGGI<D<D||t ii**,,;;]]!22;; 00!YY  
  	cXc'l+u_$**S/"G%= =s   7Fc                 P   |j                   t        _        |j                  }t        j                  j                  |j                        }t        |       t        |       |dk(  rt        |d          y |dk(  rt        t        j                  |             y t        |d          y )Nrl   r   rm   )rn   r   ro   rp   rv   r   rM   r   r   r#   r   rx   ry   r%   )rZ   rz   rp   r{   s       r   rX   zEventClient._show   ss    ||iimmDMM*cX%c'l3u_$**S/"G-r   c                    |j                   t        _        |j                  }|j                  7|j                  j                  d      D cg c]  }|j                          }}nd }|j                  7|j                  j                  d      D cg c]  }|j                          }}nd }t        |j                        }t        |j                        }t        j                  j                  |||j                  ||      }	t        |	       t        |	       |dk(  r |	d   D ]  }
t!        |
       t#                 y |dk(  rt#        t%        j&                  |	             y |	d   D ]  }
t)        |
       t#                 y c c}w c c}w )Nrc   )rP   rQ   rd   sourcesrf   rl   eventsrm   )rn   r   ro   rp   r~   rt   r   rf   r:   rP   rQ   rv   queryrd   r   r   r   r   rx   ry   r    )rZ   rz   rp   sr~   r9   rf   rP   rQ   r{   r   s              r   rY   zEventClient._stream   s>   ||<<#*.,,*<*<S*ABQqwwyBGBG99 '+yys';<!AGGI<D<D4::&" iiooEsT]]T[bfogcXX !%( u_$**S/"X E"+ C =s   FFN)__name__
__module____qualname__classmethodra   rW   rX   rY    r   r   r<   r<   C   sR    -5 -5^ (& (&T . .  r   r<   )r   r.   rerq   rx   datadogr   datadog.dogshell.commonr   r   compiler4   r   r    r#   r%   r:   objectr<   r   r   r   <module>r      sX   
   	 
   B 2::BC
,.F& Fr   