#!/usr/bin/env python # -*- coding: utf-8 -*- import sys import json import requests import base64 import pymysql import time def send_msg(region_map_result, project_need_migrate, leak_project, gardener_eks_need_clean, gardener_project_need_hibernated, gardener_cluster_need_clean, gardener_cluster_need_leak, eks_need_clean, project_need_hibernated, cluster_need_clean, cluster_need_leak, count, eks_project_list, project_billing_abnormal, tenant_billing_compare, gardener_tenant_billing_compare, gardener_project_billing_abnormal): feishu_webhook = "https://open.feishu.cn/open-apis/bot/v2/hook/1f7b6856-20c4-42e8-b160-ac2cfe3e394a" msg_dict = dict() msg_dict['msg_type'] = 'post' msg_dict['content'] = { "post": { "zh_cn": { "title": "AWS Resource Checking", "content": [ [{ "tag": "text", "text": "+++++++++++++++++Reusult Summary+++++++++++++++\n" }, { "tag": "text", "text": "check region bills result is:%s" % region_map_result },{ "tag": "text", "text": "\n++++++++++++++++region bills++++++++++++++++" },{ "tag": "text", "text": "\nThose projects need to be migrated to other aws account:%s" % project_need_migrate },{ "tag": "text", "text": "\nhose projects have resource leak:%s" % leak_project },{ "tag": "text", "text": "\n+++++++++++++++gardener clusters resource leak+++++++++++++++++" },{ "tag": "text", "text": "\nThose projects may have abnormal bills:%s" % gardener_eks_need_clean },{ "tag": "text", "text": "\nThose projects may need hibernated:%s" % gardener_project_need_hibernated },{ "tag": "text", "text": "\nThose clusters need to be deleted:%s" % gardener_cluster_need_clean },{ "tag": "text", "text": "\nThose clusters may be have resource leak:%s" % gardener_cluster_need_leak },{ "tag": "text", "text": "\n+++++++++++++++eks clusters resource leak+++++++++++++++++" },{ "tag": "text", "text": "\nThose projects may have abnormal bills:%s" % eks_need_clean },{ "tag": "text", "text": "\nThose projects may need hibernated:%s" % project_need_hibernated },{ "tag": "text", "text": "\nThose clusters need to be deleted:%s" % cluster_need_clean },{ "tag": "text", "text": "\nThose clusters may be have resource leak:%s" % cluster_need_leak },{ "tag": "text", "text": "\n+++++++++++++++total eks project+++++++++++++++++" },{ "tag": "text", "text": "\nTotal eks count:%s, detail:%s" % (count, eks_project_list) },{ "tag": "text", "text": "\n+++++++++++++++eks aws and dbaas bills+++++++++++++++++" },{ "tag": "text", "text": "\nThose projects may have abnormal bills:%s, all tenant detail:%s" % (project_billing_abnormal, tenant_billing_compare) },{ "tag": "text", "text": "\n+++++++++++++++gardener aws and dbaas bills+++++++++++++++++" },{ "tag": "text", "text": "\nThose projects may have abnormal bills:%s, all tenant detail:%s" % (gardener_tenant_billing_compare, gardener_project_billing_abnormal) }] ] } } } msg_j = json.dumps(msg_dict) requests.post(feishu_webhook, data=msg_j, headers={'Content-Type': 'application/json'})