Edit File: notifications_helper.cpython-311.pyc
� ����L(�e������������������������f�����d�dl�mZ�d�dlZd�dlZd�dlZd�dlZd�dlmZmZm Z �dZ �G�d��de������������ZdS�)�����)�absolute_importN)�Dict�Union�IterablezAleksandr Shyshatskyc��������������������r�����e�Zd�ZdZdZdZd��Zd��Zd��Zd��Z d��Z ed ����������������Zd ��Z d��Zd��Zd ��Zd��Zd��ZdS�)�NotificationsHelperzb Helper for our StatsNotifier plugin, contains logic related to notification periods z/var/lve/statsnotifier_last.tsz%/var/lve/statsnotifier_timestamps.binc�����������������������i�|�_���������i�|�_��������d|�_��������t����������j��������t ����������������������|�_��������|�������������������������������������d�S�)N���)�_users_notification_info�_resellers_notification_info�_admin_notify_time�logging� getLogger�__name__�_log�_load_from_persistent_storage��selfs��� ��/builddir/build/BUILDROOT/lve-stats-4.2.1-1.el8.x86_64/opt/cloudlinux/venv/lib/python3.11/site-packages/lvestats/lib/notifications_helper.py�__init__zNotificationsHelper.__init__���sF������(*��%�,.��)�"$����%�h�/�/�� �� �*�*�,�,�,�,�,�����c����������������������|�������������������������������������|�_��������t����������j�����������������������������|�j��������������������sdS� �t ����������|�j��������d������������5�}t����������j��������|������������\��|�_ ��������|�_ ��������ddd�������������dS�#�1�swxY�w�Y���dS�#�t����������t����������f$�r�|�j �����������������������������d�������������Y�dS�w�xY�w)z� Load information about periods from persistent storage. Admin timestamp contains in separate file, in order to make it backwards-compatible with old logic N�rbz(Cannot load data from persistent storage)�_read_ts_from_filer ����os�path�exists�RESELLERS_NOTIFICATIONS_STORAGE�open�pickle�loadr���r����IOError�EOFErrorr���� exception�r����fs��� r���r���z1NotificationsHelper._load_from_persistent_storage%���s#������#'�"9�"9�";�";����w�~�~�d�B�C�C�� ��F� M��d�:�D�A�A�� b�Q�SY�S^�_`�Sa�Sa�P��-�t�/P� b�� b�� b�� b�� b�� b�� b�� b�� b�� b�� b�� b����� b�� b�� b�� b�� b�� b����"�� M�� M�� M��I��� K�L�L�L�L�L�L� M���s6����B��"B�8B��B � B��B � B��+C��Cc������������������4����|�����������������������|�j��������������������� �t����������|�j��������d������������5�}t ����������j��������|�j��������|�j��������f|d��������������ddd�������������dS�#�1�swxY�w�Y���dS�#�t����������$�r�|�j ��������� ��������������������d�������������Y�dS�w�xY�w)z� Save information about periods on disk. Admin timestamp contains in separate file, plain text. Resellers info is pickle'd and saved into other file. �wb����)�protocolNz+Unable to save resellers timestamps to file)�_save_ts_to_filer ���r���r���r ����dumpr���r���r"���r����warningr%���s��� r����save_to_persistent_storagez.NotificationsHelper.save_to_persistent_storage6���s������ ���d�5�6�6�6� M��d�:�D�A�A�� o�Q���T�:�D�<]�^�`a�lm�n�n�n�n� o�� o�� o�� o�� o�� o�� o�� o�� o�� o�� o�� o����� o�� o�� o�� o�� o�� o���� M�� M�� M��I���K�L�L�L�L�L�L� M���s4����A/��$A"�A/��"A&�&A/��)A&�*A/��/$B�Bc����������������������� �t����������|�j��������d������������5�}|���������������������t����������|�������������������������d�d�d��������������d�S�#�1�swxY�w�Y���d�S�#�t����������$�r�|�j�����������������������������d�������������Y�d�S�w�xY�w)N�wz&Unable to save admin timestamp to file)r����STATSNOTIFIER_LAST_TS�write�strr"���r���r-���)r����tsr&���s��� r���r+���z$NotificationsHelper._save_ts_to_fileE���s������� H��d�0�#�6�6�� !�!�����B��� � � � !�� !�� !�� !�� !�� !�� !�� !�� !�� !�� !�� !����� !�� !�� !�� !�� !�� !���� H�� H�� H��I���F�G�G�G�G�G�G� H���s3����A��#A�A��A�A��A�A��$A<�;A<c����������� �������z���� �t����������|�j��������d������������5�}t����������|����������������������������������������������������������������������������������}|cd�d�d��������������S�#�1�swxY�w�Y���d�S�#�t ����������$�r�Y�dS�t����������$�r>}|�j�����������������������������d|�j���������dt����������|�������������d��������������Y�d�}~dS�d�}~ww�xY�w)N�rr ���zUnable to read z (�)) r���r1����float�readline�rstripr"���� ValueErrorr���r-���r3���)r���r&���r4����es��� r���r���z&NotificationsHelper._read_ts_from_fileM���s����� ��d�0�#�6�6�� �!��1�:�:�<�<�.�.�0�0�1�1��� �� �� �� �� �� �� �� �� �� �� �� ����� �� �� �� �� �� ����� �� �� ��2�2��� �� �� ��I����$�:T�:T�:T�VY�Z[�V\�V\�V\�V\�]�^�^�^��2�2�2�2�2����� ���s@����A&��5A�A&��A�A&�� A�!A&��& B:�3 B:�<3B5�5B:c�������������������(�����t����������j�����������������������S�)zr Get current timestamp. In future, we may do some things here, like "round(time / 60**2)" )�time��r���r����_get_current_timestampz*NotificationsHelper._get_current_timestampY���s��������y�{�{�r���c�����������������������|�������������������������������������}|D�](}|�j�����������������������������d||�������������||�j��������|<����)dS�)zY Mark resellers as notified. S aves current timestamp in memory. z(Reseller marked as notified at %s for %sN)r@���r����debugr����r����resellers_idr4����reseller_ids��� r����mark_resellers_notifiedz+NotificationsHelper.mark_resellers_notifiedb���s[�������� (� (� *� *��'�� @�� @�K��I�O�O�F��K�X�X�X�=?�D�-�k�:�:� @�� @r���c�����������������������|�������������������������������������}|D�](}|�j�����������������������������d||�������������||�j��������|<����)dS�)zU Mark users as notified. Saves current timestamp in memory. z%Users marked as notified at %s for %sN)r@���r���rB���r���rC���s��� r����mark_users_notifiedz'NotificationsHelper.mark_users_notifiedm���sW�������� (� (� *� *��'�� <�� <�K��I�O�O�C�R��U�U�U�9;�D�)�+�6�6� <�� <r���c�����������������������|�j������������������������������dt����������j�����������������������������������|������������������������������������|�_��������dS�)zU Mark admin as notified. Saves current timestamp in memory. zAdmin marked as notified at %sN)r���rB���r>���r@���r ���r���s��� r����mark_admin_notifiedz'NotificationsHelper.mark_admin_notifiedx���s;������� � ���8�$�)�+�+�F�F�F�"&�"=�"=�"?�"?����r���c������������������n�����|�������������������������������������|�j�����������������������������|d������������z ��}||k����S�)zk Check if reseller's users need to be notified (period is more than time elapsed) r ���)r@���r����get�r���rE���� notify_period�time_since_last_checks��� r����users_need_notificationz+NotificationsHelper.users_need_notification����s;�������!%� ;� ;� =� =��@]�@a�@a�bm�oq�@r�@r� r��$�}�4�4r���c������������������n�����|�������������������������������������|�j�����������������������������|d������������z ��}||k����S�)zl Check if reseller himself needs to be notified (period is more than time elapsed) r ���)r@���r���rL���rM���s��� r����reseller_need_notificationz.NotificationsHelper.reseller_need_notification����s;�������!%� ;� ;� =� =��@a�@e�@e�fq�su�@v�@v� v��$�}�4�4r���c������������������B�����|�j���������|z���|������������������������������������k�����S�)za Check if admin needs to be notified (period is more than time elapsed) )r ���r@���)r���rN���s��� r����admin_need_notificationz+NotificationsHelper.admin_need_notification����s#��������&��6��9T�9T�9V�9V�V�Vr���N)r���� __module__�__qualname__�__doc__r1���r���r���r���r.���r+���r����staticmethodr@���rF���rH���rJ���rP���rR���rT���r?���r���r���r���r������s����������������� �=��&M�#�-��-��-�M��M��M�" M�� M�� M�H��H��H� �� �� ��������\�� @�� @�� @� <�� <�� <�@��@��@�5��5��5�5��5��5�W��W��W��W��Wr���r���) � __future__r���r���r���r ���r>����typingr���r���r���� __author__�objectr���r?���r���r����<module>r]������s�������'��&��&��&��&��&������� � � � �� � � � �������(��(��(��(��(��(��(��(��(��(� #� �FW��FW��FW��FW��FW�&��FW��FW��FW��FW��FWr���