def IpmiInterfaces(self): api = ZabbixApi(self.api_url, self.username, self.password) api.user_login() ipaddress = api.get_lastvalue(self.host_name, 'ssh.run[dcmi]') api.create_host_interface(self.host_name, '', ipaddress, 1, '623', 3, 1) api.set_ipmi_setting(self.host_name, -1, 4, "admin", "admin") api.attach_host_group(self.host_name, "OCP Servers") product_name = commands.getoutput('ipmitool -I lanplus -H ' + ipaddress + ' -U ' + 'admin' + ' -P ' + 'admin' + ' -A MD5 fru') product_name = commands.getoutput( 'echo "' + product_name + '" | grep "Product Name" | cut -d: -f2 | tr -d " "') api.attach_templates(self.host_name, 'Template OCP ' + product_name) schedule = Schedule(self.host_name) proxy_name = schedule.candidate_proxy print proxy_name if proxy_name != '': agent_ipaddress = api.get_interface_ipaddress(self.host_name, '1') proxy_ipaddress = api.get_interface_ipaddress(proxy_name, '1') commands.getoutput("/bin/sh " + self.path + "/action/update_agent_conf.sh " + agent_ipaddress + " " + proxy_ipaddress) api.detach_templates(self.host_name, 'Template SSH Agent') api.delete_host_interface(self.host_name)
def update_agent_conf(api_url, username, password, host_name, proxy_name): api = ZabbixApi(api_url, username, password) api.user_login() agent_ipaddress = api.get_interface_ipaddress(host_name, '1') proxy_ipaddress = api.get_interface_ipaddress(proxy_name, '1') cmd = "/bin/sh %s/action/update_agent_conf.sh %s %s" % (os.path.abspath(os.path.dirname(__file__)), agent_ipaddress, proxy_ipaddress) result = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) return True
def suggest_candidate_proxy(self): """ ToDo """ api = ZabbixApi(self.api_url, self.username, self.password) api.user_login() proxies = api.get_proxy_list() ipmi_ip = api.get_interface_ipaddress(self.host_name, '3') setting = self.rule_data proxy_name = '' for j in setting: flag = '' if proxy_name != '': break for i in [0, 1, 2, 3]: ip = int(ipmi_ip.split(".")[i]) from_ip = int(setting[j]["from"].split(".")[i]) to_ip = int(setting[j]["to"].split(".")[i]) if flag == 'from' and from_ip < ip: proxy_name = j break elif flag == 'from' and from_ip == ip: if i == 3: proxy_name = j break else: flag == 'from' continue elif flag == 'from' and from_ip > ip: break elif flag == 'to' and to_ip < ip: break elif flag == 'to' and to_ip == ip: if i == 3: proxy_name = j break else: flag == 'to' continue elif flag == 'to' and to_ip > ip: proxy_name = j break elif i == 3 and ip == to_ip: proxy_name = j break elif i == 3 and ip == from_ip: proxy_name = j break elif from_ip == to_ip and to_ip == ip: continue elif from_ip < to_ip and from_ip == ip: flag = 'from' continue elif from_ip < to_ip and to_ip == ip: flag = 'to' continue elif from_ip < ip and ip < to_ip: proxy_name = j break else: break candidate_proxy = proxy_name print "Proxy: %s" % candidate_proxy return proxy_name
def suggest_candidate_proxy(self): """ ToDo """ rule_key = "agent_ip" api = ZabbixApi(self.api_url, self.username, self.password) api.user_login() proxies = api.get_proxy_list() agent_ip = api.get_interface_ipaddress(self.host_name, '1') if self.rule_data.has_key(rule_key): print "error" proxy_name = '' ip = agent_ip.split(".") for proxy_define in self.rule_data[rule_key].keys(): flag = '' if proxy_name != '': break from_ip = self.rule_data[rule_key][proxy_define]["from"].split(".") to_ip = self.rule_data[rule_key][proxy_define]["to"].split(".") for i in [0, 1, 2, 3]: if flag == 'from' and int(from_ip[i]) < int(ip[i]): proxy_name = proxy_define break elif flag == 'from' and int(from_ip[i]) == int(ip[i]): if i == 3: proxy_name = proxy_define break else: flag == 'from' continue elif flag == 'from' and int(from_ip[i]) > int(ip[i]): break elif flag == 'to' and int(to_ip[i]) < int(ip[i]): break elif flag == 'to' and int(to_ip[i]) == int(ip[i]): if i == 3: proxy_name = proxy_define break else: flag == 'to' continue elif flag == 'to' and int(to_ip[i]) > int(ip[i]): proxy_name = proxy_define break elif i == 3 and int(ip[i]) == int(to_ip[i]): proxy_name = proxy_define break elif i == 3 and int(ip[i]) == int(from_ip[i]): proxy_name = proxy_define break elif int(from_ip[i]) == int(to_ip[i]) and int(to_ip[i]) == int(ip[i]): continue elif int(from_ip[i]) < int(to_ip[i]) and int(from_ip[i]) == int(ip[i]): flag = 'from' continue elif int(from_ip[i]) < int(to_ip[i]) and int(to_ip[i]) == int(ip[i]): flag = 'to' continue elif int(from_ip[i]) < int(ip[i]) and int(ip[i]) < int(to_ip[i]): proxy_name = proxy_define break else: break print "Proxy: %s" % proxy_name return proxy_name