当前位置: 首页 > news >正文

微信网站开发合同泽成seo网站排名

微信网站开发合同,泽成seo网站排名,商场网站建设,肇庆 网站建设 骏域网站有时候被ZABBIX监控的主机可能需要关机重启等维护操作,为了在此期间不触发告警,需要创建主机的维护任务,以免出现误告警 ZABBIX本身有这个API可供调用(不同版本细节略有不同,本次用的ZABBIX6.*),实现批量化建立主机的维护任务 无论哪种方式(IP列表,主机描述,或IP子网)创建维护…

有时候被ZABBIX监控的主机可能需要关机重启等维护操作,为了在此期间不触发告警,需要创建主机的维护任务,以免出现误告警

ZABBIX本身有这个API可供调用(不同版本细节略有不同,本次用的ZABBIX6.*),实现批量化建立主机的维护任务

无论哪种方式(IP列表,主机描述,或IP子网)创建维护,都是向maintenance.create这个方法传递参数的过程,除了起始和终止的时间,最主要的一个参数就是hostids这个参数,它是一个列表(也可以是单个hostid)

    def create_host_maintenance(self,names,ips,starttimes,stoptimes):starts=self.retimes(starttimes)stops=self.retimes(stoptimes)data = json.dumps({"jsonrpc":"2.0","method":"maintenance.create","params": {"name": names,"active_since": starts,"active_till": stops,#"hostids": [ "12345","54321" ],"hostids": ips,"timeperiods": [{"timeperiod_type": 0,"start_date": starts,#"start_time": 0,zabbix6不用这个参数,低版本的有用"period": int(int(stops)-int(starts))}]},"auth": self.authID,"id": 1,})request = urllib2.Request(self.url, data)for key in self.header:request.add_header(key, self.header[key])try:result = urllib2.urlopen(request)except URLError as e:print "Error as ", eelse:response = json.loads(result.read())result.close()print "maintenance is created!"

1.简单说明hostids这个列表参数产生的过程

按IP列表产生hostids的LIST,并调用方法创建维护

def djmaintenanceiplist(self,ipliststr="strs",area="none",byip="none"):lists = []if area=="none":                                #通过IP列表来创建维护,只向函数传递ipliststr这个参数,其它参数为空for line in ipliststr.splitlines():con = line.split()ipaddr = con[0].strip()hostids = self.host_getbyip(ipaddr)if hostids != "error" and hostids not in lists:lists.append(hostids)return listselse:if area !="ip" and ipliststr != "strs":    #按主机描述匹配创建维护,ipliststr参数因定为strs,area参数为主机描述,byip参数为空(因为网络环境的原因,本例弃用这个条件)sqls="select hostid from zabbixdb.hosts where name like '%"+area+"%' "tests=pysql.conn_mysql()datas=tests.query_mysqlrelists(sqls)if datas != "error":for ids, in datas:if ids not in lists:lists.append(ids)else:if byip != "none":                     #按主机IP子网创建维护,byip参数不为空(因为网络环境的原因,本例弃用这个条件)sqls = "select hosts.hostid from zabbixdb.hosts,zabbixdb.interface where `hosts`.hostid=interface.hostid and (interface.ip like '%" + byip + "%' or hosts.name like '%" + byip + "%')"tests = pysql.conn_mysql()datas = tests.query_mysqlrelists(sqls)if datas != "error":for ids, in datas:if ids not in lists:lists.append(ids)return listsdef djiplist(self,starttime,stoptime,strlins):  #strlins为IP列表的参数,可由WEB前端传递进来test = ZabbixTools()test.user_login()lists = test.djmaintenanceiplist(strlins)nowtime = str(time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime(time.time())))test.create_host_maintenance(nowtime, lists, starttime, stoptime)

按主机描述和IP子网产生hostids的LIST,并调用方法创建维护

def djdescript(self,starttime,stoptime,descstr,ipnets="none"):lists = []if descstr != "ip":          #descstr参数不为ip的时候,表示根据主机的描述信息匹配创建维护,此时不传递innets参数for line in descstr.splitlines():con = line.split()descstrnew = con[0].strip()sqls = "select hostid from dbname.hosts where name like '%" + descstrnew + "%' "tests = pysql.conn_mysql()datas = tests.query_mysqlrelists(sqls)if datas != "error":for ids, in datas:if ids not in lists:lists.append(ids)else:if ipnets != "none":    #ipnets参数不为空,表示按照IP子网匹配创建维护,此时descstr参数一定为"ip"sqls = "select hosts.hostid from dbname.hosts,dbname.interface where `hosts`.hostid=interface.hostid and (interface.ip like '%" + ipnets + "%' or hosts.name like '%" + ipnets + "%')"tests = pysql.conn_mysql()datas = tests.query_mysqlrelists(sqls)if datas != "error":for ids, in datas:if ids not in lists:lists.append(ids)test = ZabbixTools()test.user_login()nowtime = str(time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime(time.time())))test.create_host_maintenance(nowtime, lists, starttime, stoptime)

2.create_host_maintenance和djmaintenanceiplist,及djdescript函数调用方法的说明

时间转换函数self.retimes,将用户传递/的"%Y-%m-%d %H:%M:%S"日期时间转换为时间时间戳

    def retimes(self,times):timeArray = time.strptime(times, "%Y-%m-%d %H:%M:%S")timestamp = time.mktime(timeArray)return timestamp

self.host_getbyip(ipaddr)通过主机IP获取zabbix的hostid,这个方法应用很广泛

函数中的self.authID通过zabbix的API 的"user.login"方法获取,参考ZABBIX官方文档

    def host_getbyip(self,hostip):data = json.dumps({"jsonrpc":"2.0","method":"host.get","params":{"output":["hostid","name","status","available"],"filter": {"ip": hostip,"custom_interfaces":0}},"auth":self.authID,"id":1,})request = urllib2.Request(self.url, data)for key in self.header:request.add_header(key, self.header[key])try:result = urllib2.urlopen(request)except URLError as e:if hasattr(e, 'reason'):print 'We failed to reach a server.'print 'Reason: ', e.reasonelif hasattr(e, 'code'):print 'The server could not fulfill the request.'print 'Error code: ', e.codeelse:response = json.loads(result.read())result.close()lens=len(response['result'])if lens > 0:return response['result'][0]['hostid']else:print "error "+hostipreturn "error"
pysql.conn_mysql()的实现
#coding:utf-8
import pymysql
class conn_mysql:def __init__(self):self.db_host = 'zabbixdbip'self.db_user = 'dbusername'self.db_passwd = 'dbuserpassword'self.database = "dbname"def query_mysqlrelists(self, sql):conn = pymysql.connect(host=self.db_host, user=self.db_user, passwd=self.db_passwd,database=self.database)cur = conn.cursor()cur.execute(sql)data = cur.fetchall()cur.close()conn.close()#print data# 查询到有数据则进入行判断,row有值且值有效则取指定行数据,无值则默认第一行if data != None and len(data) > 0:return data#调用方式:for ids, in datas:else:return "error"#此方法返回的数据不含数据库字段的列表,如果要返回包含列名(KEY)的字典列表,则:conn = pymysql.connect(host=self.db_host, user=self.db_user, passwd=self.db_passwd,database=self.database,cursorclass=pymysql.cursors.DictCursor)  解决:tuple indices must be integers, not str

3.VIEWS.PY及前端和前端伟递参数的说明

views.py对应的方法

#@login_required
def zabbixmanage(request):if request.method=="POST":uptime = request.POST.get('uptime')downtime= request.POST.get('downtime')UTC_FORMAT = "%Y-%m-%dT%H:%M"utcTime = datetime.datetime.strptime(uptime, UTC_FORMAT)uptime = str(utcTime + datetime.timedelta(hours=0))utcTime = datetime.datetime.strptime(downtime, UTC_FORMAT)downtime = str(utcTime + datetime.timedelta(hours=0))if request.POST.has_key('iplists'):try:sqlstr=request.POST.get("sqlstr")u1=upproxy.ZabbixTools()  #前面的python文件名为upproxy.py,类名为ZabbixToolsu1.djiplist(uptime,downtime,sqlstr)except Exception:return render(request,"zbx1.html",{"login_err":"FAILSTEP1"})if request.POST.has_key('descs'):try:sqlstr = request.POST.get("sqlstr")u1 = upproxy.ZabbixTools()  u1.djdescript(uptime,downtime,sqlstr)except Exception:return render(request,"zbx1.html",{"login_err":"FAILSTEP2"})if request.POST.has_key('ipnets'):try:sqlstr = request.POST.get("sqlstr")u1 = upproxy.ZabbixTools()u1.djdescript(uptime,downtime,"ip",sqlstr)except Exception:return render(request,"zbx1.html",{"login_err":"FAILSTEP3"})

HTML的简单写法,不太会写,很潦草

<!DOCTYPE html>
<html lang="en">
<head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>ZABBIXMANAGE</title>
</head>
<body><div id="container" class="cls-container"><div id="bg-overlay" ></div><div class="cls-header cls-header-lg"><div class="cls-brand"><h3>ZABBIX主机维护模式</h3><h4>开始时间小于结束时间</h4></div></div><div class="cls-content"><div class="cls-content-sm panel"><div class="panel-body"><form id="loginForm" action="{% url 'zabbixmanage' %}" method="POST"> {% csrf_token %}<div class="form-group"><div class="input-group"><div class="input-group-addon"><i class="fa fa-user"></i></div><textarea type="text" class="form-control" name="sqlstr" placeholder="IP列表,关键字或者IP网段" style="width:300px;height:111px"></textarea></br></div></div></br></br>开始时间:<input type="datetime-local" name="uptime"></br></br>结束时间:<input type="datetime-local" name="downtime"></br></br><p class="pad-btm">按IP列表维护:按行输入IP列表加入维护,一行一个IP,多行输入</p><p class="pad-btm">按关键字匹配:主机描述信息的关键字匹配的加入维护,一般用于虚拟机宿主机和关键字匹配</p><p class="pad-btm">匹配子网关键字维护:IP网段匹配的加入维护,一次填写一个子网,多个子网多次设置,写法示例:172.16.</p><button class="btn btn-success btn-block" type="submit" name="iplists"><b>按IP列表维护一般情况用这个就行</b></button></br></br><button class="btn btn-success btn-block" type="submit" name="descs"><b>按关键字匹配</b></button><button class="btn btn-success btn-block" type="submit" name="ipnets"><b>匹配子网关键字维护</b></button><h4 style="color: red"><b>{{ login_err }}</b></h4></form></div></div></div>		</div>
</body>
</html>

跑起来大约是这个界面,用户填写主机IP列表,或匹配的描述,或子网的信息,选好时间,点个按钮就能实现批量的维护任务


文章转载自:
http://dinncostapelia.zfyr.cn
http://dinncopromptness.zfyr.cn
http://dinncoquackishly.zfyr.cn
http://dinncobiassed.zfyr.cn
http://dinncomacrocyst.zfyr.cn
http://dinncocondiments.zfyr.cn
http://dinncohesiflation.zfyr.cn
http://dinncohypotaxis.zfyr.cn
http://dinncootalgic.zfyr.cn
http://dinncogermule.zfyr.cn
http://dinncovarech.zfyr.cn
http://dinncothyself.zfyr.cn
http://dinncocwar.zfyr.cn
http://dinncoexnihilo.zfyr.cn
http://dinncosuperactinide.zfyr.cn
http://dinncodoris.zfyr.cn
http://dinncoendogenous.zfyr.cn
http://dinncoboulangerie.zfyr.cn
http://dinncowastage.zfyr.cn
http://dinncomangabey.zfyr.cn
http://dinncoknuckler.zfyr.cn
http://dinncovelvety.zfyr.cn
http://dinncoever.zfyr.cn
http://dinncovoe.zfyr.cn
http://dinncodaa.zfyr.cn
http://dinncotubicolous.zfyr.cn
http://dinncojellaba.zfyr.cn
http://dinncomiss.zfyr.cn
http://dinncotreponeme.zfyr.cn
http://dinncoeyewitness.zfyr.cn
http://dinncoguaranty.zfyr.cn
http://dinncounbend.zfyr.cn
http://dinncocobia.zfyr.cn
http://dinncosavageness.zfyr.cn
http://dinncobreathless.zfyr.cn
http://dinncolexigraphy.zfyr.cn
http://dinncoprefecture.zfyr.cn
http://dinncowrt.zfyr.cn
http://dinncodoubler.zfyr.cn
http://dinnconosogenetic.zfyr.cn
http://dinncoanticarcinogenic.zfyr.cn
http://dinncobocce.zfyr.cn
http://dinncowhirleybird.zfyr.cn
http://dinncoflimsy.zfyr.cn
http://dinncosachsen.zfyr.cn
http://dinncomonopolize.zfyr.cn
http://dinncohaemostatic.zfyr.cn
http://dinncoseparative.zfyr.cn
http://dinncocardiopulmonary.zfyr.cn
http://dinncocyc.zfyr.cn
http://dinncocardsharper.zfyr.cn
http://dinncoagi.zfyr.cn
http://dinncosaleslady.zfyr.cn
http://dinncorefrigerant.zfyr.cn
http://dinncofugue.zfyr.cn
http://dinncogenealogy.zfyr.cn
http://dinncoconsummate.zfyr.cn
http://dinncophotocinesis.zfyr.cn
http://dinncopinger.zfyr.cn
http://dinncopeplos.zfyr.cn
http://dinncoanthropolater.zfyr.cn
http://dinncoevadible.zfyr.cn
http://dinncogrecism.zfyr.cn
http://dinncomapper.zfyr.cn
http://dinncohasten.zfyr.cn
http://dinncorondel.zfyr.cn
http://dinncoeschewal.zfyr.cn
http://dinncoclubwoman.zfyr.cn
http://dinncochrysler.zfyr.cn
http://dinncosignificative.zfyr.cn
http://dinncobiocellate.zfyr.cn
http://dinnconjord.zfyr.cn
http://dinncocalamander.zfyr.cn
http://dinncoyoick.zfyr.cn
http://dinncoclinometer.zfyr.cn
http://dinncoapocalyptical.zfyr.cn
http://dinncoplacentography.zfyr.cn
http://dinncothan.zfyr.cn
http://dinnconeontology.zfyr.cn
http://dinncotheravadin.zfyr.cn
http://dinncointerdental.zfyr.cn
http://dinncothimphu.zfyr.cn
http://dinncotrepid.zfyr.cn
http://dinncoblasphemer.zfyr.cn
http://dinncostirring.zfyr.cn
http://dinncoaomen.zfyr.cn
http://dinncomastoiditis.zfyr.cn
http://dinncodifformity.zfyr.cn
http://dinncodenbighshire.zfyr.cn
http://dinncolaudanum.zfyr.cn
http://dinncofloozie.zfyr.cn
http://dinncoprimary.zfyr.cn
http://dinncodecretal.zfyr.cn
http://dinncodrave.zfyr.cn
http://dinncoseizing.zfyr.cn
http://dinncomicrosection.zfyr.cn
http://dinncounware.zfyr.cn
http://dinncomacrostylous.zfyr.cn
http://dinncochupatti.zfyr.cn
http://dinncoconvertaplane.zfyr.cn
http://www.dinnco.com/news/125618.html

相关文章:

  • 免费做请帖的网站北京专业网站优化
  • 做网站团队seo优化方案案例
  • 做家政服务类网站的要求微信运营工具
  • Wordpress 普通图片裁剪win10最强性能优化设置
  • 莆田网站建设公司渠道营销推广方案
  • wordpress 页面代码seo关键词优化经验技巧
  • 网站升级 html泉州seo报价
  • 网站系统性能定义成都网站优化公司
  • 政府网站群集约化建设郑州seo优化服务
  • 做网站企业湛江seo网站管理
  • 网站中图片中间是加号怎么做seo具体seo怎么优化
  • 怎样建一个个人网站抖音引流推广一个30元
  • 怎样做网商网站上海关键词优化报价
  • 政府网站集约化建设范围信息推广平台
  • 做视频网站审核编辑有假么云南网络推广服务
  • 电商网站与企业网站区别windows10优化软件
  • 分类网站建设方案东莞营销网站建设直播
  • 外贸网站建设 东莞软文写作公司
  • 莱芜论坛24小时主题帖seo优化包括
  • 网站收录说明游戏推广代理app
  • 做外链权重高的女性网站企业网络营销策略案例
  • 外管局网站 报告怎么做市场调研报告万能模板
  • 平面设计接单多少钱一单seo专员是什么
  • 茂名企业建站程序三亚百度推广地址
  • 怎么样才能创建自己的网站上海seo优化公司
  • 宣城网站推广郑州seo线下培训
  • 怎么做轴承网站免费手机网站建站平台
  • 寻找做网站云南网络推广服务
  • 南通购物网站建设怎么快速优化关键词排名
  • 网站免费大全qq代刷网站推广免费