2016-07-12 15:18:29 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from selenium import selenium
|
|
|
|
from selenium.webdriver.common.by import By
|
|
|
|
from selenium.webdriver.support.ui import WebDriverWait, Select
|
|
|
|
from selenium.webdriver.support import expected_conditions as EC
|
|
|
|
from agent_functions import search_agent
|
|
|
|
from common_functions_60 import *
|
|
|
|
|
|
|
|
import random, time
|
|
|
|
import string
|
|
|
|
|
|
|
|
|
2016-07-15 13:59:51 +02:00
|
|
|
def create_module(module_type,*args,**kwargs):
|
|
|
|
if module_type=='network_server':
|
|
|
|
create_network_server_module(*args,**kwargs)
|
|
|
|
elif module_type=='data_server':
|
|
|
|
create_data_server_module(*args,**kwargs)
|
|
|
|
|
2016-08-17 17:14:25 +02:00
|
|
|
def create_network_server_module(driver,agent_name=None,module_name=None,component_group=None,type_of_module=None,network_component=None,min_warning=None,max_warning=None,min_critical=None,max_critical=None,ip=None,tag_name=None,description=None):
|
2016-07-12 15:39:03 +02:00
|
|
|
|
|
|
|
# component_group -> Example: Remote ICMP network agent (latency)
|
|
|
|
# network_component -> Example: Host Alive
|
|
|
|
|
2016-08-17 17:14:25 +02:00
|
|
|
#The type_of_module variable is optional, but required if component_group and network_component variables are specified
|
2016-07-12 15:18:29 +02:00
|
|
|
|
2016-07-15 13:59:51 +02:00
|
|
|
if agent_name != None:
|
|
|
|
search_agent(driver,agent_name)
|
|
|
|
driver.find_element_by_xpath('//ul[@class="mn"]/li/a/img[@data-title="Manage"]').click()
|
|
|
|
driver.find_element_by_xpath('//ul[@class="mn"]/li/a/img[@data-title="Modules"]').click()
|
2016-08-17 17:14:25 +02:00
|
|
|
|
2016-07-12 15:18:29 +02:00
|
|
|
Select(driver.find_element_by_id("moduletype")).select_by_visible_text("Create a new network server module")
|
2016-08-17 17:14:25 +02:00
|
|
|
driver.find_element_by_xpath('//*[@id="main"]/form/table/tbody/tr/td[5]/input').click()
|
2016-07-12 15:18:29 +02:00
|
|
|
|
2016-07-12 15:39:03 +02:00
|
|
|
driver.find_element_by_xpath('//a[contains(.,"Advanced options")]').click()
|
2016-07-12 15:18:29 +02:00
|
|
|
|
|
|
|
if min_warning != None:
|
|
|
|
|
|
|
|
driver.find_element_by_id("text-min_warning").clear()
|
|
|
|
driver.find_element_by_id("text-min_warning").send_keys(min_warning)
|
|
|
|
|
|
|
|
if max_warning != None:
|
|
|
|
|
|
|
|
driver.find_element_by_id("text-max_warning").clear()
|
|
|
|
driver.find_element_by_id("text-max_warning").send_keys(min_warning)
|
|
|
|
|
|
|
|
if min_critical != None:
|
|
|
|
|
|
|
|
driver.find_element_by_id("text-min_critical").clear()
|
|
|
|
driver.find_element_by_id("text-min_critical").send_keys(min_critical)
|
|
|
|
|
|
|
|
if max_critical != None:
|
|
|
|
|
|
|
|
driver.find_element_by_id("text-max_critical").clear()
|
|
|
|
driver.find_element_by_id("text-max_critical").send_keys(max_critical)
|
|
|
|
|
|
|
|
if ip != None:
|
|
|
|
|
|
|
|
driver.find_element_by_id("text-ip_target").clear()
|
|
|
|
driver.find_element_by_id("text-ip_target").send_keys(ip)
|
|
|
|
|
2016-07-12 15:39:03 +02:00
|
|
|
if component_group!= None and network_component!= None:
|
|
|
|
Select(driver.find_element_by_id("network_component_group")).select_by_visible_text(component_group)
|
|
|
|
Select(driver.find_element_by_id("network_component")).select_by_visible_text(network_component)
|
|
|
|
|
|
|
|
else:
|
|
|
|
driver.find_element_by_id("text-name").clear()
|
|
|
|
driver.find_element_by_id("text-name").send_keys(module_name)
|
2016-08-17 17:14:25 +02:00
|
|
|
Select(driver.find_element_by_id("id_module_type")).select_by_visible_text(type_of_module)
|
2016-07-12 15:18:29 +02:00
|
|
|
|
2016-07-13 10:16:15 +02:00
|
|
|
if module_name != None:
|
2016-07-15 13:59:51 +02:00
|
|
|
time.sleep(3)
|
2016-07-13 10:16:15 +02:00
|
|
|
driver.find_element_by_id("text-name").clear()
|
|
|
|
driver.find_element_by_id("text-name").send_keys(module_name)
|
|
|
|
|
2016-07-13 11:09:19 +02:00
|
|
|
if tag_name != None:
|
|
|
|
|
|
|
|
Select(driver.find_element_by_id("id_tag_available")).select_by_visible_text(tag_name)
|
|
|
|
driver.find_element_by_xpath('//*[@id="right"]').click()
|
|
|
|
|
|
|
|
if description != None:
|
|
|
|
|
|
|
|
driver.find_element_by_id("textarea_description").clear()
|
|
|
|
driver.find_element_by_id("textarea_description").send_keys(description)
|
|
|
|
|
2016-07-12 15:18:29 +02:00
|
|
|
driver.find_element_by_id("submit-crtbutton").click()
|
2016-07-12 15:39:03 +02:00
|
|
|
|
2016-07-13 13:23:03 +02:00
|
|
|
|
2016-08-17 17:14:25 +02:00
|
|
|
def create_data_server_module(driver,module_name,agent_name=None,type_of_module=None,min_warning=None,max_warning=None,min_critical=None,max_critical=None,tag_name=None,description=None):
|
2016-07-13 13:23:03 +02:00
|
|
|
|
2016-08-17 17:14:25 +02:00
|
|
|
# type_of_module -> Example: Generic numeric
|
2016-07-13 13:23:03 +02:00
|
|
|
|
2016-08-17 17:14:25 +02:00
|
|
|
# The type_of_module variable is Generic numeric by default
|
2016-07-15 13:59:51 +02:00
|
|
|
|
|
|
|
if agent_name != None:
|
|
|
|
search_agent(driver,agent_name)
|
|
|
|
driver.find_element_by_xpath('//ul[@class="mn"]/li/a/img[@data-title="Manage"]').click()
|
|
|
|
driver.find_element_by_xpath('//ul[@class="mn"]/li/a/img[@data-title="Modules"]').click()
|
|
|
|
|
2016-07-13 13:23:03 +02:00
|
|
|
Select(driver.find_element_by_id("moduletype")).select_by_visible_text("Create a new data server module")
|
2016-08-17 13:01:33 +02:00
|
|
|
driver.find_element_by_xpath('//*[@id="main"]/form/table/tbody/tr/td[5]/input').click()
|
2016-07-13 13:23:03 +02:00
|
|
|
|
|
|
|
driver.find_element_by_xpath('//a[contains(.,"Advanced options")]').click()
|
2016-07-12 15:18:29 +02:00
|
|
|
|
2016-07-13 13:23:03 +02:00
|
|
|
driver.find_element_by_id("text-name").clear()
|
|
|
|
driver.find_element_by_id("text-name").send_keys(module_name)
|
|
|
|
|
2016-08-17 17:14:25 +02:00
|
|
|
if type_of_module != None:
|
2016-07-13 13:23:03 +02:00
|
|
|
|
2016-08-17 17:14:25 +02:00
|
|
|
Select(driver.find_element_by_id("id_module_type")).select_by_visible_text(type_of_module)
|
2016-07-13 13:23:03 +02:00
|
|
|
|
|
|
|
if min_warning != None:
|
|
|
|
|
|
|
|
driver.find_element_by_id("text-min_warning").clear()
|
|
|
|
driver.find_element_by_id("text-min_warning").send_keys(min_warning)
|
|
|
|
|
|
|
|
if max_warning != None:
|
|
|
|
|
|
|
|
driver.find_element_by_id("text-max_warning").clear()
|
|
|
|
driver.find_element_by_id("text-max_warning").send_keys(min_warning)
|
|
|
|
|
|
|
|
if min_critical != None:
|
|
|
|
|
|
|
|
driver.find_element_by_id("text-min_critical").clear()
|
|
|
|
driver.find_element_by_id("text-min_critical").send_keys(min_critical)
|
|
|
|
|
|
|
|
if max_critical != None:
|
|
|
|
|
|
|
|
driver.find_element_by_id("text-max_critical").clear()
|
|
|
|
driver.find_element_by_id("text-max_critical").send_keys(max_critical)
|
|
|
|
|
|
|
|
if tag_name != None:
|
|
|
|
|
|
|
|
Select(driver.find_element_by_id("id_tag_available")).select_by_visible_text(tag_name)
|
|
|
|
driver.find_element_by_xpath('//*[@id="right"]').click()
|
|
|
|
|
|
|
|
if description != None:
|
|
|
|
|
|
|
|
driver.find_element_by_id("textarea_description").clear()
|
|
|
|
driver.find_element_by_id("textarea_description").send_keys(description)
|
|
|
|
|
|
|
|
driver.find_element_by_id("submit-crtbutton").click()
|
|
|
|
|
2016-07-12 15:18:29 +02:00
|
|
|
def delete_module (driver,agent_name,module_name):
|
|
|
|
|
|
|
|
search_agent(driver,agent_name)
|
|
|
|
driver.find_element_by_xpath('//ul[@class="mn"]/li/a/img[@data-title="Manage"]').click()
|
|
|
|
driver.find_element_by_xpath('//ul[@class="mn"]/li/a/img[@data-title="Modules"]').click()
|
|
|
|
|
|
|
|
driver.find_element_by_id("text-search_string").clear()
|
|
|
|
driver.find_element_by_id("text-search_string").send_keys(module_name)
|
|
|
|
|
|
|
|
driver.find_element_by_id("submit-filter").click()
|
|
|
|
driver.find_element_by_id("checkbox-id_delete").click()
|
|
|
|
driver.find_element_by_xpath('//*[@id="table2-1-9"]/a/img').click()
|
|
|
|
|
|
|
|
alert = driver.switch_to_alert()
|
|
|
|
alert.accept()
|
|
|
|
|
2016-09-15 16:18:25 +02:00
|
|
|
def search_module (driver,agent_name,module_name,go_to_module=False):
|
2016-07-12 15:18:29 +02:00
|
|
|
|
|
|
|
search_agent(driver,agent_name)
|
|
|
|
driver.find_element_by_xpath('//ul[@class="mn"]/li/a/img[@data-title="Manage"]').click()
|
|
|
|
driver.find_element_by_xpath('//ul[@class="mn"]/li/a/img[@data-title="Modules"]').click()
|
|
|
|
|
|
|
|
driver.find_element_by_id("text-search_string").clear()
|
|
|
|
driver.find_element_by_id("text-search_string").send_keys(module_name)
|
|
|
|
|
|
|
|
driver.find_element_by_id("submit-filter").click()
|
2016-08-17 17:14:25 +02:00
|
|
|
|
2016-09-15 16:18:25 +02:00
|
|
|
if go_to_module == True:
|
|
|
|
driver.find_element_by_xpath('//a[contains(.,"'+module_name+'")]').click()
|
|
|
|
|
2016-08-17 17:14:25 +02:00
|
|
|
|
2016-07-12 15:18:29 +02:00
|
|
|
|