示例#1
0
 def post(self):
     parser = reqparse.RequestParser()
     parser.add_argument('page', type=int, default=1, help='')
     parser.add_argument('minute', type=int, default=10, help='')
     args = parser.parse_args()
     page = args.get('page')
     minute = args.get('minute')
     setting_col.update_many(
         {'key': 'task'},
         {'$set': {
             'key': 'task',
             'page': page,
             'minute': minute
         }},
         upsert=True)
     try:
         os.kill(
             setting_col.find_one({
                 'key': 'task'
             }).get('pid'), signal.SIGHUP)
     except ProcessLookupError:
         pass
     result = list(setting_col.find({}, {'_id': 0}))
     data = {'status': 201, 'msg': '设置成功', 'result': result}
     return jsonify(data)
示例#2
0
 def post(self):
     parser = reqparse.RequestParser()
     parser.add_argument('from', type=str, help='From (sender email)')
     parser.add_argument('host', type=str, help='SMTPServer Host')
     parser.add_argument('port', type=int, help='SMTPServer Port')
     parser.add_argument('tls',
                         type=inputs.boolean,
                         default=False,
                         help='Force TLS')
     parser.add_argument('username', type=str, help='Username')
     parser.add_argument('password', type=str, help='Password')
     parser.add_argument('domain', type=str, help='System URL Host')
     parser.add_argument('enabled',
                         type=inputs.boolean,
                         default=False,
                         help='Enabled Mail Notice')
     parser.add_argument('test',
                         type=inputs.boolean,
                         default=False,
                         help='Test Mail Notice')
     args = parser.parse_args()
     __setting = args
     setting_col.update_many({'key': 'mail'},
                             {'$set': dict({'key': 'mail'}, **__setting)},
                             upsert=True)
     result = setting_col.find_one({'key': 'mail'}, {'_id': 0})
     data = {'status': 201, 'msg': '设置成功', 'result': result}
     return jsonify(data)
示例#3
0
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument('argument',
                            type=str,
                            default=request.host,
                            help='setting argument')
        parser.add_argument('value',
                            type=str,
                            default=request.host,
                            help='setting value')
        parser.add_argument('unique',
                            type=inputs.boolean,
                            default=False,
                            help='setting unique')
        args = parser.parse_args()
        value = args.get('value')
        argument = args.get('argument')

        setting_col.update_many({
            'key': 'system',
            'argument': argument
        }, {'$set': {
            'key': 'system',
            'argument': argument,
            'value': value
        }},
                                upsert=True)

        result = list(setting_col.find({}, {'_id': 0}))
        data = {'status': 201, 'msg': '设置成功', 'result': result}
        return jsonify(data)
示例#4
0
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument('webhook_url', type=str, help='webhook_url')
        parser.add_argument('enabled',
                            type=inputs.boolean,
                            default=False,
                            help='enabled Notice')
        parser.add_argument('test',
                            type=inputs.boolean,
                            default=False,
                            help='test')
        parser.add_argument('www_host',
                            type=str,
                            help='Hostname (for webhook notice link)')
        args = parser.parse_args()
        if args.get('test'):
            if not args.get('webhook_url'):
                data = {'status': 404, 'msg': '错误的webhook地址', 'result': []}
                return jsonify(data)
            test_content = {
                "msgtype": "markdown",
                "markdown": {
                    "title": "GitHub泄露",
                    "text": '### 规则名称: [钉钉告警测试]()'
                },
                "at": {
                    "atMobiles": [],
                    "isAtAll": False
                }
            }

            response = requests.post(args.get('webhook_url'),
                                     json=test_content)
            print(response.json())
            print(response.text())
            print(response.ok)

            data = {'status': 201, 'msg': '已发送,请查收', 'result': []}
            return jsonify(data)
        webhook_setting = args
        setting_col.update_many(
            {'key': 'webhook'},
            {'$set': dict({'key': 'webhook'}, **webhook_setting)},
            upsert=True)
        print(webhook_setting)
        result = setting_col.find_one({'key': 'webhook'}, {'_id': 0})
        data = {'status': 201, 'msg': '设置成功', 'result': result}
        return jsonify(data)
示例#5
0
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument('webhook', type=str, help='DingTalk WebHook URL')
        parser.add_argument('domain', type=str, help='System URL Host')
        parser.add_argument('enabled', type=inputs.boolean, default=False, help='Enabled DingTalk Notice')
        parser.add_argument('test', type=inputs.boolean, default=False, help='Test DingTalk Notice')
        args = parser.parse_args()
        __setting = args
        __setting['webhook'] = str(args.get('webhook'))
        if not (urlparse(__setting.get('webhook')).netloc == 'oapi.dingtalk.com' and urlparse(
                __setting.get('webhook')).scheme == 'https'):
            data = {'status': 400, 'msg': '错误的webhook地址', 'result': []}
            return jsonify(data)
        if args.get('test'):
            test_content = {
                "msgtype": "markdown",
                "markdown": {"title": "GitHub泄露",
                             "text": '### 规则名称: [钉钉告警测试]()'
                             },
                "at": {
                    "atMobiles": [

                    ],
                    "isAtAll": False
                }
            }

            response = requests.post(
                args.get('webhook'),
                json=test_content)
            if response.ok:
                if response.json().get('errmsg') == 'ok':
                    data = {'status': 201, 'msg': '已发送,请前往钉钉群查看', 'result': []}
                else:
                    data = {'status': 400, 'msg': '发送失败,请检查webhook地址', 'result': []}
                return jsonify(data)
            else:
                data = {'status': 400, 'msg': '发送失败,请检查服务器网络', 'result': []}
                return jsonify(data)
        setting_col.update_many({'key': 'dingtalk'}, {'$set': dict({'key': 'dingtalk'}, **__setting)},
                                upsert=True)
        result = setting_col.find_one({'key': 'dingtalk'}, {'_id': 0})
        data = {'status': 201, 'msg': '设置成功', 'result': result}
        return jsonify(data)