本文整理汇总了Python中hc.api.models.Check.grace方法的典型用法代码示例。如果您正苦于以下问题:Python Check.grace方法的具体用法?Python Check.grace怎么用?Python Check.grace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hc.api.models.Check
的用法示例。
在下文中一共展示了Check.grace方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: checks
# 需要导入模块: from hc.api.models import Check [as 别名]
# 或者: from hc.api.models.Check import grace [as 别名]
def checks(request):
if request.method == "GET":
q = Check.objects.filter(user=request.user)
doc = {"checks": [check.to_dict() for check in q]}
return JsonResponse(doc)
elif request.method == "POST":
check = Check(user=request.user)
check.name = str(request.json.get("name", ""))
check.tags = str(request.json.get("tags", ""))
if "timeout" in request.json:
check.timeout = td(seconds=request.json["timeout"])
if "grace" in request.json:
check.grace = td(seconds=request.json["grace"])
check.save()
# This needs to be done after saving the check, because of
# the M2M relation between checks and channels:
if request.json.get("channels") == "*":
check.assign_all_channels()
return JsonResponse(check.to_dict(), status=201)
# If request is neither GET nor POST, return "405 Method not allowed"
return HttpResponse(status=405)
示例2: create_check
# 需要导入模块: from hc.api.models import Check [as 别名]
# 或者: from hc.api.models.Check import grace [as 别名]
def create_check(request):
if request.method != "POST":
return HttpResponse(status=405)
check = Check(user=request.user)
check.name = str(request.json.get("name", ""))
check.tags = str(request.json.get("tags", ""))
if "timeout" in request.json:
check.timeout = td(seconds=request.json["timeout"])
if "grace" in request.json:
check.grace = td(seconds=request.json["grace"])
check.save()
response = {
"ping_url": check.url()
}
return JsonResponse(response, status=201)
示例3: create_check
# 需要导入模块: from hc.api.models import Check [as 别名]
# 或者: from hc.api.models.Check import grace [as 别名]
def create_check(request):
if request.method == "GET":
code = 200
response = {
"checks": [
{
"name": check.name,
"ping_url": check.url(),
"tags": check.tags,
"timeout": int(check.timeout.total_seconds()),
"grace": int(check.grace.total_seconds()),
# "channels": check.channels,
}
for check in Check.objects.filter(user=request.user)
]
}
elif request.method == "POST":
check = Check(user=request.user)
check.name = str(request.json.get("name", ""))
check.tags = str(request.json.get("tags", ""))
if "timeout" in request.json:
check.timeout = td(seconds=request.json["timeout"])
if "grace" in request.json:
check.grace = td(seconds=request.json["grace"])
check.save()
# This needs to be done after saving the check, because of
# the M2M relation between checks and channels:
if request.json.get("channels") == "*":
check.assign_all_channels()
code = 201
response = {"ping_url": check.url()}
else:
return HttpResponse(status=405)
return JsonResponse(response, status=code)
示例4: create_check
# 需要导入模块: from hc.api.models import Check [as 别名]
# 或者: from hc.api.models.Check import grace [as 别名]
def create_check(request):
if request.method != "POST":
return HttpResponse(status=405)
check = Check(user=request.user)
check.name = str(request.json.get("name", ""))
check.tags = str(request.json.get("tags", ""))
if "timeout" in request.json:
check.timeout = td(seconds=request.json["timeout"])
if "grace" in request.json:
check.grace = td(seconds=request.json["grace"])
check.save()
# This needs to be done after saving the check, because of
# the M2M relation between checks and channels:
if request.json.get("channels") == "*":
check.assign_all_channels()
response = {
"ping_url": check.url()
}
return JsonResponse(response, status=201)