本文整理汇总了Python中monitors.Monitor.createMonitor方法的典型用法代码示例。如果您正苦于以下问题:Python Monitor.createMonitor方法的具体用法?Python Monitor.createMonitor怎么用?Python Monitor.createMonitor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类monitors.Monitor
的用法示例。
在下文中一共展示了Monitor.createMonitor方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addcheck_page
# 需要导入模块: from monitors import Monitor [as 别名]
# 或者: from monitors.Monitor import createMonitor [as 别名]
def addcheck_page(cname):
verify = verifyLogin(
app.config['SECRET_KEY'], app.config['COOKIE_TIMEOUT'], request.cookies)
if verify:
user = User()
user.get('uid', verify, g.rdb_conn)
data = startData(user)
data['active'] = 'dashboard'
data['url'] = '/dashboard/monitors/' + cname
tmpl = 'monitors/' + cname + '.html'
data['js_bottom'] = ['monitors/monitorlist.js', 'monitors/base.js', 'monitors/' + cname + '.js']
# Check Users Status
if user.status != "active":
data['url'] = '/dashboard/mod-subscription'
tmpl = 'member/mod-subscription.html'
else:
# Get list of reactions and validate that there are some
data['reactions'] = user.getReactions(g.rdb_conn)
# Proces the form
cform = __import__(
"monitorforms." + cname, globals(), locals(), ['CheckForm'], -1)
form = cform.CheckForm(request.form)
if form.__contains__("timer"):
form.timer.choices = data['choices']
reactchoices = []
for key in data['reactions'].keys():
reactchoices.append(
(data['reactions'][key]['id'],
data['reactions'][key]['name']))
form.reactions.choices = reactchoices
if request.method == 'POST':
if form.validate():
monitor = Monitor()
monitor.name = form.name.data
monitor.ctype = cname
monitor.uid = user.uid
monitor.status = "queued"
monitor.url = None
tmpdata = {}
for item in form.__iter__():
tmpdata[item.name] = item.data
monitor.data = tmpdata
# Check if the user already exceeds their limit
if monitor.count(user.uid, g.rdb_conn) < data['limit']:
# Create the monitor if all checks out
results = monitor.createMonitor(g.rdb_conn)
else:
results = "toomany"
if results == "exists":
print("/dashboard/monitors/{0} - \
Monitor already exists".format(cname))
flash('{0} seems to already exist. \
Try using a different name.'.format(
monitor.name), 'danger')
elif results is False:
print("/dashboard/monitors/{0} - \
Monitor creation failed".format(cname))
flash('Could not create monitor.', 'danger')
elif results == 'toomany':
stathat.ez_count(
app.config['STATHAT_EZ_KEY'],
app.config['ENVNAME'] + ' Too many health checks',
1)
flash('You have too many monitors. \
Please upgrade your plan or clean \
up old ones.', 'danger')
print("/dashboard/monitors/{0} - \
Monitor creation failed: toomany".format(cname))
else:
stathat.ez_count(
app.config['STATHAT_EZ_KEY'],
app.config['ENVNAME'] + ' Monitor Added', 1)
print("/dashboard/monitors/%s - \
Monitor creation successful") % cname
flash('Monitor "{0}" successfully added.'.format(
monitor.name), 'success')
newmonitor = Monitor()
newmonitor.get(results, g.rdb_conn)
if newmonitor.uid == user.uid:
data['monitor'] = {
'cid': newmonitor.cid,
'name': newmonitor.name,
'uid': newmonitor.uid,
'ctype': newmonitor.ctype,
'url': newmonitor.url,
'data': newmonitor.data
}
else:
print("/dashboard/monitors/{0} - \
Monitor creation failed: Form invalid".format(cname))
flash('Form is not valid.', 'danger')
page = render_template(tmpl, data=data, form=form)
return page
else:
flash('Please Login.', 'warning')
return redirect(url_for('user.login_page'))