monitor_host_edit.py
1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from .models import MonitorHost, db
from sqlalchemy import and_
from app.util.component.ApiTemplate import ApiTemplate
import uuid
class Api(ApiTemplate):
api_name = "编辑主机配置"
def para_check(self):
if not self.para.get("srcid"):
raise Exception("缺乏host参数")
def process(self):
# 返回结果
res = {}
res["data"] = {}
try:
srcid = self.para.get("srcid") # server
passwd = self.para.get("passwd")
host_name = self.para.get("host_name")
# Catalog.query.filter_by(guid=self.para.get("guid")).update({"name":self.para.get("name")})
if passwd or host_name:
monitor_host = MonitorHost.query.filter_by(srcid=srcid)
if passwd:
monitor_host.update({"password": passwd})
if host_name:
monitor_host.update({"host_name": host_name})
db.session.commit()
res["result"] = True
res["message"] = "更新成功".format(srcid)
except Exception as e:
db.session.rollback()
raise e
return res
api_doc = {
"tags": ["监控接口"],
"parameters": [
{"name": "srcid",
"in": "formData",
"type": "string",
"description": "srcid值",
"required": "true"},
{"name": "host_name",
"in": "formData",
"type": "string",
"description": "主机名"},
{"name": "passwd",
"in": "formData",
"type": "string",
"description": "密码"}
],
"responses": {
200: {
"schema": {
"properties": {
}
}
}
}
}