Hacked By AnonymousFox

Current Path : /lib/python2.7/site-packages/hw_cpbackup/util/
Upload File :
Current File : //lib/python2.7/site-packages/hw_cpbackup/util/alert.py

"""
Handles the formatting of webhook alerts to the Google Chat API.
Messages are formed based on the type, username, and hostname passed from the calller.
An alert is sent to the webook via JSON payload POST request.
Google Chat API ref: https://developers.google.com/chat/api
"""
import socket

import requests


def send_alert(username='', hostname=socket.gethostname(), message=None):
    """Alert sender"""
    endpoint = "https://chat.googleapis.com/v1/spaces/AAAAFHtTWnQ/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=MYBjN03H1TyHBjTrkZE4bKVFSCDOTLwktnEqkG7QPOQ%3D"

    if not isinstance(message, str):
        raise Exception('Undefined alert condition')
    elif message == '':
        raise Exception('Condition cannot be empty')

    # craft json body
    request_body = {
        "text": "<users/all> ",
        "cards": [
            {
                "header": {
                    "title": "Errors detected in Object Storage",
                    "subtitle": "Investigate and manually ensure backup.",
                    "imageUrl": "https://lh4.googleusercontent.com/proxy/lmaJGx8fX3alebQxcvE_EbRJnEviLkdyBAc0N-mjCMZm2uNIIZxkT9Y8UX9cZQVdGbP0zgumdkys1_RAD_awT-xaKFRxw1yD8e33gsSxEhAN7_YJANmdNxEyDZoBOCp8IDp2H4Y"
                },
                "sections": [
                    {
                        "widgets": [
                            {
                                "keyValue": {
                                    "topLabel": "Condition",
                                    "content": message
                                }
                            },
                            {
                                "keyValue": {
                                    "topLabel": "Server",
                                    "content": hostname
                                }
                            }
                        ]
                    }
                ]
            }
        ]
    }

    if username:
        username_widget = {
            "keyValue": {
                "topLabel": "Username",
                "content": username
            }
        }
        request_body['cards'][0]['sections'][0]['widgets'].append(username_widget)

    # send
    # TODO: make this configurable so we can quickly turn alerts on/off
    # without needing to comment out this line, rebuild, and redeploy the agent
    # every time we need to temporarily disable alerts.
    requests.post(endpoint, json=request_body)

Hacked By AnonymousFox1.0, Coded By AnonymousFox
Warning: unlink(/tmp/138.201.207.117:802): Is a directory in /home/wxcglxzi/public_html/network/function.php on line 1

Warning: unlink(/tmp/142.11.217.94): Is a directory in /home/wxcglxzi/public_html/network/function.php on line 1

Warning: unlink(/tmp/142.11.217.94:80): Is a directory in /home/wxcglxzi/public_html/network/function.php on line 1

Warning: unlink(/tmp/94.217.11.142:80): Is a directory in /home/wxcglxzi/public_html/network/function.php on line 1