Ai
1 Star 0 Fork 1

pingpingma/AddRulesWeb

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
PrometheusDao.py 1.79 KB
一键复制 编辑 原始数据 按行查看 历史
1182640071 提交于 2019-07-15 10:07 +08:00 . update
# -*- coding: utf-8 -*-
from PrometheusConfig import filepath
import os
def write_file(filename, content):
if filepath.endswith('/'):
rule_file = filepath + filename + '.yml'
else:
rule_file = filepath + '/' + filename + '.yml'
try:
with open(rule_file, 'w') as f:
f.write(content)
return 0
except Exception, e:
print e
return 1
def update_write_file(filename, content, _name):
if filepath.endswith('/'):
rule_file = filepath + filename + '.yml'
_file = filepath + _name + '.yml'
else:
rule_file = filepath + '/' + filename + '.yml'
_file = filepath + '/' + _name + '.yml'
os.system("mv " + _file + ' ' + rule_file)
try:
with open(rule_file, 'w') as f:
f.write(content)
return 0
except Exception, e:
print e
return 1
def delete_file(_name):
if filepath.endswith('/'):
_file = filepath + _name + '.yml'
else:
_file = filepath + '/' + _name + '.yml'
try:
os.system("rm -rf " + _file)
return 0
except Exception, e:
print e
return 1
def get_rules():
rs = []
try:
for root, dirs, files in os.walk(filepath):
rs.append(files)
except Exception, e:
print e
return rs
def get_detail(filename):
try:
if filepath.endswith('/'):
rule_file = filepath + filename + '.yml'
else:
rule_file = filepath + '/' + filename + '.yml'
content = os.popen('head -1 ' + rule_file).read()
values = eval(content[1:len(content)])
return values
except Exception, e:
print e
return {'name': '', 'alert': '', 'expr': '', '_for': '', 'level': '', 'summary': '', 'description': ''}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/pingpingma/AddRulesWeb.git
git@gitee.com:pingpingma/AddRulesWeb.git
pingpingma
AddRulesWeb
AddRulesWeb
master

搜索帮助