import os
import sys

sys.path.append(os.path.dirname(sys.path[0]))

from utils.common_util import CommonUtil


def check_hadoop():
    import os
    try:
        output = str(os.popen('hdfs dfsadmin -report').read())
        lines = output.split("\n")
        for line in lines:
            line = line.strip()
            if line.startswith("Live datanodes"):
                print("success")
                print(line)
            if line.startswith("Dead datanodes"):
                print(line)
                content = "hadoop节点存在宕机情况，请检查！"
                users = [
                    'wujicang',
                    'huangjian',
                    'fangxingjun',
                    'chenjianyun',
                    'wangrui4'
                ]
                print("发送微信消息中！")
                CommonUtil.send_wx_msg(users, "hadoop健康检查", content)
                print("success")
            pass
    except:
        pass

    pass


if __name__ == '__main__':
    check_hadoop()
    pass
