/usr/share/web-monitoring-tool/__pycache__
� ��G&Sng� �� � d dl Z d dlZd dlZd dlZd dlmZmZ g d�ZddgZd� Z d#d�Z d$d �Zd� Zd� Z d � Zd� Zd$d�Zd� Zd� Zd$d�Zd� Zd� Zd� Zd� Zd� Zd� Zedk �r ed� � Z e� � e j ej dd� dg d�� � \ ZZnE# e j $ r8Z e! e"e � � � � e � � ej# d� � Y dZ [ ndZ [ ww xY w eD ]j\ Z$Z%e$dv r e � � ej# � � �#e$d v r e� � �2e$d!v r e� � �Ae$d"v r e� � �P e � � ej# d� � �kdS # e&$ r Z'e�( e'� � Y dZ'['dS dZ'['ww xY wdS )%� N)�init_wmt_sentry_client�setup_logger)�add_cron� erase_cron�remove_cron� add_cron_task�wmt-clickhouse-reporter�wmt-email-reporterc � � t d� � t d� � t t j d dz � � t d� � t d� � t d� � t d� � d S ) N� z=Use following syntax to manage WMT cron jobs install utility:r z [OPTIONS]zOptions:z+ -i | --install : install wmt cron jobsz* -d | --delete : delete wmt cron jobsz* -u | --update : update wmt cron jobs)�print�sys�argv� � �|/builddir/build/BUILDROOT/cl-web-monitoring-tool-3.1.7-1.el9.cloudlinux.x86_64/usr/share/web-monitoring-tool/cron_control.py�usager sv � � �"�I�I�I� � I�J�J�J� �#�(�1�+�� $�%�%�%� �*���� � 7�8�8�8� � 6�7�7�7� � 6�7�7�7�7�7r Tc � � |dk r/t t t j dd� � � � � � }|dk r/t t t j dd� � � � � � } t |||||||� � } t | | |� � dS # t $ r# t j � d� � Y dS w xY w)a� Add new cron task into crontab schedule if this task or command wasn't already existed in the cron-file. :param str file_name: Name of cron-file in /etc/cron.d :param minute: Integer or char 'r' if to set random minute :param hour: Integer or char 'r' if to set random hour :param int, str day: Day number :param int, str month: Month number :param int, str day_of_week: Day of week number :param str user: Under what user do run command :param str command: What command do run :param bool check_command: If it is False, check that whole cron-task line already exists in crontab, check that command string exists instead. Default is True, check a command string. �rr �; � z"Can not add task with wrong syntaxN) �int�round�random�uniform�format_cron_taskr � TypeErrorr �stderr�write) � file_name�minute�hour�day�month�day_of_week�user�command� check_command� cron_tasks r r r s� � � ��}�}��U�6�>�!�R�0�0�1�1�2�2���s�{�{��5����2�.�.�/�/�0�0��?�$�V�T�3��{�D�RY�Z�Z� ��i��M�:�:�:�:�:��� ?� ?� ?�� ���=�>�>�>�>�>�>�?���s �,&B �)C� CFc �� � t j � d| � � } d}t j � |� � r;t |� � 5 }|� � � }ddd� � n# 1 swxY w Y t |||� � s@t |d� � 5 }|� d|z � � ddd� � n# 1 swxY w Y n# t t f$ r Y dS w xY wdS )a� Add new cron task in cron format if this task or command in this task wasn't already existed in the cron-file. :param str file_name: Name of cron-file in /etc/cron.d :param str task: Cron task in format "min hour day mon d_of_w user command" :param bool check_command: If it is False, check that whole cron-task line already exists in crontab, check that command string exists instead. Default is False, check a whole cron-task string. �/etc/cron.d/r N�az%s FT) �os�path�join�exists�open� readlines� is_in_cronr �IOError�OSError)r �taskr( �cron_file_path�content�fs r r r ; s_ � � �W�\�\�.�)�<�<�N� ��� �7�>�>�.�)�)� (��n�%�%� (���+�+�-�-�� (� (� (� (� (� (� (� (� (� (� (���� (� (� (� (��$���7�7� '��n�c�*�*� '�a������ �&�&�&� '� '� '� '� '� '� '� '� '� '� '���� '� '� '� '����W�� � � ��u�u������4sY �0C �A3�'C �3A7�7C �:A7�;$C �C�8C �C�C �C�C �C%�$C%c � � t j t j � d| � � � � dS # t t f$ r Y dS w xY w)z^ Remove cron-file from fs :param str file_name: Name of cron-file in /etc/cron.d r+ N)r- �remover. r/ r5 r4 )r s r r r R sa � � � � ��G�L�L���3�3� � � � � �� �W�� � � ���� ���s �26 �A� Ac �4 � d} t t j � d| � � d� � }|� � � dS # t t f$ r>}t j � d| �dt |� � �d�� � Y d}~dS d}~ww xY w)zZ Make cron-file empty :param str file_name: Name of cron-file in /etc/cron.d Nr+ �wzCan not erase crontab file z because � )r1 r- r. r/ �closer4 r5 r r r �str)r r9 �errs r r r ` s� � � �A����G�L�L���3�3�S� � �� ��� � � � � �� �W�� "� "� "�� �����I�I�s�3�x�x�x�x�!� "� "� "� "� "� "� "� "� "�����"���s �.A �B�3B�Bc �J � | ||||||f}|D ]}|�t d� � ��d|z S )a� Build cron-task string in the cron format :param minute: Integer or char 'r' if to set random minute :param hour: Integer or char 'r' if to set random hour :param int day: Day number :param int month: Month number :param int day_of_week: Day of week number :param str user: Under what user do run command :param str command: What command do run :return: Cron-task in the cron format :rtype: str NzWrong schedule for cron taskz%2s %2s %2s %2s %2s %10s %s)r ) r! r"