Пример #1
0
def maintenance_del(id=None):
    try:
        hostlist = []
        from app.common.zabbix import zabbix_server 
        from app.common.zabbix import get_maintenance
        id = request.args.get("id")
        data = Maintenance.query.filter(Maintenance.id == id).first()  
        hostname = data.hostname  
        ret = zabbix_server.get_hosts()
        for host in ret:
	    if hostname == host["host"]:
	        hostids=host["hostid"]
	        ret = get_maintenance(hostids)
                maintenanceid = ret[0]['maintenanceid']
                ret = zabbix_server.del_maintenance([maintenanceid])
		result_data = zabbix_server.host_status(hostid=hostids, status="0")
		print result_data
		try: 
	            db.session.query(Maintenance).filter_by(id=id).delete()
                    db.session.commit()	
		except Exception,e:
		    raise e.message
	        servers = api_action("server.get",{"output":["hostname"]})
                data = Maintenance.query.all()
	        return render_template("monitor/zabbix_maintenance.html",hostlist=servers,data=data) 
        return "200"
Пример #2
0
def maintenance_del(id=None):
    try:
        hostlist = []
        from app.common.zabbix import zabbix_server
        from app.common.zabbix import get_maintenance
        id = request.args.get("id")
        data = Maintenance.query.filter(Maintenance.id == id).first()
        hostname = data.hostname
        ret = zabbix_server.get_hosts()
        for host in ret:
            if hostname == host["host"]:
                hostids = host["hostid"]
                ret = get_maintenance(hostids)
                maintenanceid = ret[0]['maintenanceid']
                ret = zabbix_server.del_maintenance([maintenanceid])
                result_data = zabbix_server.host_status(hostid=hostids,
                                                        status="0")
                print result_data
                try:
                    db.session.query(Maintenance).filter_by(id=id).delete()
                    db.session.commit()
                except Exception, e:
                    raise e.message
                servers = api_action("server.get", {"output": ["hostname"]})
                data = Maintenance.query.all()
                return render_template("monitor/zabbix_maintenance.html",
                                       hostlist=servers,
                                       data=data)
        return "200"
Пример #3
0
def maintenance_add():
    from app.common.zabbix import zabbix_server
    from app.common.zabbix import create_maintenance
    data = dict(request.form)
    #{'name': [u'mail.shihuasuan.com'], 'time': [u'1']}
    maintenance_name = data['maintenance_name'][0]
    hostname = data["name"][0]
    time_to_go = data["time"][0]
    time_long = int(time_to_go) * 60 *60 
    ret = zabbix_server.get_hosts()
    for host in ret:
	if hostname == host["host"]:
	    hostids = host["hostid"]
	    try:
	        result = create_maintenance(maintenance_name,hostids,time_long) 
		result_data = zabbix_server.host_status(hostid=hostids, status="1")
	    except:
		return "check your maintenance_name"
	    update_time = time.strftime("%Y-%m-%d %H:%I:%S", time.localtime(time.time()))
	    add_data = {"maintenance_name":maintenance_name, "hostname":hostname, "maintenance_time":time_to_go,"update_time":update_time}
	    obj = Maintenance(**add_data)
	    db.session.add(obj)
	    try:
        	db.session.commit()
    	    except Exception,e:
        	raise Exception(e.message.split(")")[1]) 
	    return "1"
Пример #4
0
def maintenance_add():
    from app.common.zabbix import zabbix_server
    from app.common.zabbix import create_maintenance
    data = dict(request.form)
    #{'name': [u'mail.shihuasuan.com'], 'time': [u'1']}
    maintenance_name = data['maintenance_name'][0]
    hostname = data["name"][0]
    time_to_go = data["time"][0]
    time_long = int(time_to_go) * 60 * 60
    ret = zabbix_server.get_hosts()
    for host in ret:
        if hostname == host["host"]:
            hostids = host["hostid"]
            try:
                result = create_maintenance(maintenance_name, hostids,
                                            time_long)
                result_data = zabbix_server.host_status(hostid=hostids,
                                                        status="1")
            except:
                return "check your maintenance_name"
            update_time = time.strftime("%Y-%m-%d %H:%I:%S",
                                        time.localtime(time.time()))
            add_data = {
                "maintenance_name": maintenance_name,
                "hostname": hostname,
                "maintenance_time": time_to_go,
                "update_time": update_time
            }
            obj = Maintenance(**add_data)
            db.session.add(obj)
            try:
                db.session.commit()
            except Exception, e:
                raise Exception(e.message.split(")")[1])
            return "1"