def __init__(self): self.log = lib_Log.Log(PrintToConsole=True) self.Error = False self.Telnet_open = False self.TelenetTimeout = 120 self.Prompt = ">" self.log.increaseLevel()
def __init__(self, INI, deviceDescr, devNumber): self.Error = False self.log = lib_Log.Log(PrintToConsole=True) #for inhiretance from device class self.INI = INI self.deviceDescr = deviceDescr self.devNumber = devNumber self.log.increaseLevel() #Get INI Variables self.interface = self.INI.getOption(self.deviceDescr, self.devNumber, "INTERFACE") self.bindHost = self.INI.getOption(self.deviceDescr, self.devNumber, "RECEIVEIP") self.bindPort = int(self.INI.getOption(self.deviceDescr, self.devNumber, "RECEIVEPORT")) self.captureAll = self.INI.getOption(self.deviceDescr, self.devNumber, "CAPTUREALL") self.maxTime = self.INI.getOption(self.deviceDescr, self.devNumber, "CAPTURETIME") self.maxTime = int(self.maxTime) if (self.maxTime != None) else 4 Dictionary = self.INI.getOption(self.deviceDescr, self.devNumber) self.getDataDict = [] # a * in dictionary will make sure, loop runs untill timeout if self.captureAll: self.getDataDict.extend("*") self.log.printWarning("CaptureAll --> All NMEA data within %s seconds will be captured" % str(self.maxTime)) #Get All Get_ items form INI file else: for Name in Dictionary: if Name.startswith('GET_') and (Dictionary[Name].lower() == "true"): self.getDataDict.extend([Name[4:]])
def __init__(self, INI, deviceDescr, devNumber): self.Error = False self.log = lib_Log.Log(PrintToConsole=True) #for inhiretance from device class self.INI = INI self.deviceDescr = deviceDescr self.devNumber = devNumber self.log.increaseLevel() self.IP = self.INI.getOptionStr(self.deviceDescr, self.devNumber, "IP") if self.IP is None: self.log.printWarning("IP for %s%s not set" % (self.deviceDescr, self.devNumber)) self.Error = True self.User = self.INI.getOptionStr(self.deviceDescr, self.devNumber, "USER") if self.User is None: self.log.printWarning("User for %s%s not set" % (self.deviceDescr, self.devNumber)) self.Error = True self.Password = self.INI.getOptionStr(self.deviceDescr, self.devNumber, "PASSWORD") if self.Password is None: self.log.printWarning("Password for %s%s not set" % (self.deviceDescr, self.devNumber)) self.Error = True self.Port = self.INI.getOptionStr(self.deviceDescr, self.devNumber, "HTTPPORT") if self.Port is None: self.Port = "" else: self.Port = ":" + self.Port self.CommIf = ""
def __init__(self, INI, deviceDescr, devNumber): self.Error = False self.log = lib_Log.Log(PrintToConsole=True) #for inhiretance from device class self.INI = INI self.deviceDescr = deviceDescr self.devNumber = devNumber self.log.increaseLevel() self.SetPrompt() self.ipaddr = self.INI.getOption(self.deviceDescr, self.devNumber, "IP") self.getDataDict = { 'maxIfNumber': '1.3.6.1.2.1.2.1.0', 'ifDescr': '1.3.6.1.2.1.2.2.1.2', 'ifPhysAddress': '1.3.6.1.2.1.2.2.1.6', #mac adress/interface 'ifAdminStatus': '1.3.6.1.2.1.2.2.1.7', 'ifOperStatus': '1.3.6.1.2.1.2.2.1.8', 'vlanId': '1.3.6.1.4.1.9.9.68.1.2.2.1.2', 'vlanStatus': '1.3.6.1.4.1.9.9.68.1.2.2.1.3', 'vlanMembership': '1.3.6.1.4.1.9.9.68.1.2.2.1.1', 'serialNumber': '1.3.6.1.2.1.47.1.1.1.1.11.1', 'modelNumber': '1.3.6.1.2.1.47.1.1.1.1.13.1', 'softVersion': '1.3.6.1.2.1.47.1.1.1.1.10.1', 'ifInOctets': '1.3.6.1.2.1.2.2.1.10', 'ifOutOctets': '1.3.6.1.2.1.2.2.1.16', } self.ifAdminStatusList = ["", "UP", "DOWN", "TESTING"] self.ifOperStatusList = [ "", "UP", "DOWN", "Testing", "Unknown", "Dormant", "NotPresent", "LowerLayerDown" ] self.vlanStatusList = ["", "Inactive", "Active", "Shutdown"] self.vlanMembershipList = ["", "Static", "Dynamic", "MultiVlan"]
def __init__(self): # INIT CONFIG config_data = lib_config.CONFIG_DATA() # COUCH DATABASE NAME self.couchdb_name = config_data.couchdb_name # COUCH CREDENTIALS self.couch_protocol = config_data.couch_protocol self.couch_user = config_data.couch_user self.couch_password = config_data.couch_password self.couch_host = config_data.couch_host self.couch_port = config_data.couch_port url = "{}://{}:{}@{}:{}/".format(self.couch_protocol, self.couch_user, self.couch_password, self.couch_host, self.couch_port) # CREATE DATABASE create_database = self.create_database() self.vessel_number = "" self.vessel_id = "" self.backend_dir = config_data.backend_dir self.api_dir = config_data.api_dir self.web_dir = config_data.web_dir self.Error = False self.log = lib_Log.Log(PrintToConsole=True) self.log.increaseLevel()
def TimeSting_To_Sec(String, CleanUp=True): try: log = lib_Log.Log(PrintToConsole=True) if CleanUp: b = parse("{days} days {hours} hrs {minutes} mins {seconds} secs", String) if b == None: b = parse("{hours} hrs {minutes} mins {seconds} secs", String) if b == None: b = parse("{minutes} mins {seconds} secs", String) if b == None: time = 0 else: result = "0D 0H " + b["minutes"] + "M " + b[ "seconds"] + "S" else: result = "0D " + b["hours"] + "H " + b[ "minutes"] + "M " + b["seconds"] + "S" else: result = b["days"] + "D " + b["hours"] + "H " + b[ "minutes"] + "M " + b["seconds"] + "S" b = parse("{days}D {hours}H {minutes}M {seconds}S", result) if b == None: time = 0 else: Time = (float(b["days"]) * 86400) + (float(b["hours"]) * 3600) + ( float(b["minutes"]) * 60) + float(b["seconds"]) return Time except Exception as e: log.printError("%s Module Error" % sys._getframe().f_code.co_name) log.printError(str(e))
def __init__(self): """Init class""" self.Error = False self.log = lib_Log.Log(PrintToConsole=True) self.iniFiles = {} self.iniList = [] self.INI = {} self.INIcount = 1 #create Emegrency Failover INI file if not exist file = "ini/EMGFAILOVER.INI" try: fh = open(file, 'r') except: # if file does not exist, create it fh = open(file, 'w') fh.close() self.AddINI("SYSTEM.INI") self.AddINI("ini/CONFIG.INI") self.AddINI("ini/COMPLEXCONFIG.INI") self.AddINI("ini/NETWORK.INI") self.AddINI("ini/PORTFORWARDING.INI") self.AddINI("ini/FIREWALL.INI") self.AddINI("ini/EMGFAILOVER.INI") self.RemoveNoneINIs() self.iniList.sort()
def CheckHostname(INI): log = lib_Log.Log(PrintToConsole=True) log.printBoldInfo("Check Hostname") log.increaseLevel() INIHostname = INI.getOption("INFO", "VESSELNAME") if INIHostname != None: #cleanup hostname for forbidden characters INIHostname = re.sub(" ", "_", INIHostname) INIHostname = re.sub('[^a-zA-Z0-9_.]', '', INIHostname) #get hostname Hostname = subprocess.check_output(["hostname"]) Hostname = Hostname.strip().decode('ascii') if Hostname != INIHostname: log.printWarning("changing hostname from '%s' to '%s'" % (Hostname, INIHostname)) #adjust /etc/hosts CommandString = "sed -ie s/" + Hostname + "/" + INIHostname + "/g /etc/hosts" if lib_Bash.Bash(str(CommandString)): log.printError("Failed changing '/etc/hosts'") #adjust /etc/hostname CommandString = "sed -ie s/" + Hostname + "/" + INIHostname + "/g /etc/hostname" if lib_Bash.Bash(str(CommandString)): log.printError("Failed changing '/etc/hostname'") #reboot log.printWarning("Warning system will reboot in 20 seconds") time.sleep(20) os.system("sudo shutdown -r now") else: log.printInfo("Hostname is still correct")
def __init__(self, INI): self.INI = INI self.vessel_number = INI.getOption("INFO","IMO") # INIT CONFIG config_data = lib_config.CONFIG_DATA() # COUCH DATABASE NAME self.couchdb_name = config_data.couchdb_name # COUCH CREDENTIALS self.couch_protocol = config_data.couch_protocol self.couch_user = config_data.couch_user self.couch_password = config_data.couch_password self.couch_host = config_data.couch_host self.couch_port = config_data.couch_port self.remote_couch_protocol = config_data.remote_couch_protocol self.remote_couch_user = config_data.remote_couch_user self.remote_couch_password = config_data.remote_couch_password self.remote_couch_host = config_data.remote_couch_host self.remote_couch_port = config_data.remote_couch_port self.remote_db_name = config_data.remote_db_name self.log = lib_Log.Log(PrintToConsole = True)
def __init__(self, INI, memory): self.memory = memory self.log = lib_Log.Log(PrintToConsole=True) self.Error = False self.INI = INI self.config_data = lib_config.CONFIG_DATA() return
def __init__(self): self.log = lib_Log.Log(PrintToConsole=True) self.Error = False self.SSH_open = False self.SSH = paramiko.SSHClient() self.Prompt = ">" self.log.increaseLevel() self.ActiveMultiSession = False
def Get_Var_String(String=""): log = lib_Log.Log(PrintToConsole=True) String = re.sub('[=]', '', String) #Remove space in beginning and ending, and the \n #String = String[1:-2] String = String.strip() String = "[" + String + "]\n" return String
def __init__(self, INI, deviceDescr, devNumber): self.Error = False self.log = lib_Log.Log(PrintToConsole=True) #for inhiretance from device class self.INI = INI self.deviceDescr = deviceDescr self.devNumber = devNumber self.log.increaseLevel()
def __init__(self,INI): self.log = lib_Log.Log(PrintToConsole=True) self.Error = False self.INI = INI self.ReadError = False self.Renew = False self.ClearFailoverVariables() self.ServerIP = "185.95.73.13" self.ServerVPNIP = "185.95.73.13" self.Ping = lib_ICMP.Ping(self.ServerIP) self.PingVPN = lib_ICMP.Ping(self.ServerVPNIP) self.StandardDefaultGW = self.GetDefaultGateway() #create variables for priorities (datacounter) self.CounterDatatypes = ("rx_bytes","tx_bytes") self.CounterInterfaces = "tun1" temp = lib_LocalInterface.ReadBandwith(datatypes = self.CounterDatatypes, interfaces = self.CounterInterfaces) self.rxBytes = temp["tun1"]["rx_bytes"] self.txBytes = temp["tun1"]["tx_bytes"] self.MailInternalSend = False self.MailExternalSend = False ExternalMailDelay = self.INI.getOptionInt("FAILOVERGENERAL","EXTERNALMAILDELAY") if ExternalMailDelay is None: #if no delay is set, we set to 30 min ExternalMailDelay = 60 * 30 self.log.printWarning("ExternalMailDelay not defined in ini-file, set to %s seconds" % ExternalMailDelay) InternalMailDelay = self.INI.getOptionInt("FAILOVERGENERAL","INTERNALMAILDELAY") if InternalMailDelay is None: #if no delay is set, we set to 15 min InternalMailDelay = 60 * 15 self.log.printWarning("InternalMailDelay not defined in ini-file, set to %s seconds" % InternalMailDelay) self.ExternalMailDelay = ExternalMailDelay self.InternalMailDelay = InternalMailDelay self.ExternalMailSend = False self.InternalMailSend = False self.ChangedInterfaceTime = None self.InterfaceBeforeLastMail = None self.LastSuccessVPNPing = time.time() #how long does an iterface deserves to be "burned" before we can use it again (seconds) self.InterfaceBurnRestoreTime = 60 * 10 #after how long with unsuccessfull vpn pings an interface becomes "burned" self.InterfaceBurnTime = 60 * 1 #initialize time of burn to now, so counter starts here self.InterfaceBurningTime = time.time() self.BurnedInterface = None #checktimes is used for how often we need to check some parameters self.checktime = time.time() #create SQL instance # self.sql = lib_SQLdb.Database() self.couch_db = lib_CouchDB.COUCH_DATABASE() config_data = lib_config.CONFIG_DATA() self.config_interface = config_data.interface
def __init__(self, DestHost): self.log = lib_Log.Log(PrintToConsole=True) self.Error = False self.log.increaseLevel() self.destHost = DestHost #new from here self.community = 'public' self.remotePort = 161 self.snmpVersion = 2 #2 => 2c self.tables = {} self.snmpSession = netsnmp.Session(Version=self.snmpVersion, DestHost=self.destHost, Community=self.community, RemotePort = self.remotePort, Timeout = 500000, #micro-sec Retries = 2, UseNumeric = 1, #using OIDs ) self.oidConversion = {} self.textualConversion = {} self.textualConversion['ifMib_ifAdminStatus'] = {1 : 'up', 2: 'down', 3: 'testing' } self.textualConversion['ifMib_ifOperStatus'] = {1 : 'up', 2: 'down', 3: 'testing', 4: 'unknown', 5: 'dormant', 6: 'notPresent', 7: 'lowerLayerDown' } self.textualConversion['ifMib_IANAifType'] = {1 : 'other', 6: 'ethernetCsmacd', 33: 'rs232', 53: 'propVirtual' } self.textualConversion['PowerEthernetMib_pethPsePortAdminEnable'] = {1 : 'true', 2: 'false' } self.textualConversion['PowerEthernetMib_pethPsePortDetectionStatus'] = {1 : 'disabled', 2: 'searching', 3: 'deliveringPower', 4: 'fault', 5: 'test', 6: 'otherFault'} self.textualConversion['PowerEthernetMib_pethMainPseOperStatus'] = {1 : 'on', 2: 'off', 3: 'faulty' } self.textualConversion['EntityMib_entPhysicalClass'] = {1: 'other', 2: 'unkown', 3: 'chassis', 4: 'backplane', 5: 'container', 6: 'powerSupply', 7: 'fan', 8: 'sensor', 9: 'module', 10: 'port', 11: 'stack', 12: 'cpu'} self.textualConversion['QBridgeMib_dot1qVlanStatus'] = {1: 'other', 2: 'permanent', 3: 'dynamicGvrp'} #general SNMPv2MIB definition self.oidConversion.update({ '.1.3.6.1.2.1.1.1' : {'name': 'sysDescr'}, '.1.3.6.1.2.1.1.2' : {'name': 'sysObjectID'}, '.1.3.6.1.2.1.1.3' : {'name': 'sysUptime'}, '.1.3.6.1.2.1.1.4' : {'name': 'sysContact'}, '.1.3.6.1.2.1.1.5' : {'name': 'sysName'}, '.1.3.6.1.2.1.1.6' : {'name': 'sysLocation'}, '.1.3.6.1.2.1.1.7' : {'name': 'sysServices'}, }) self.SNMPv2MIB_varList = netsnmp.VarList( netsnmp.Varbind('.1.3.6.1.2.1.1.1'), #netsnmp.Varbind('.1.3.6.1.2.1.1.2'), netsnmp.Varbind('.1.3.6.1.2.1.1.3'), netsnmp.Varbind('.1.3.6.1.2.1.1.4'), netsnmp.Varbind('.1.3.6.1.2.1.1.5'), netsnmp.Varbind('.1.3.6.1.2.1.1.6'), #netsnmp.Varbind('.1.3.6.1.2.1.1.7'), )
def String_Parse(String="", OriginalKeys="", ReplaceKeys="", Section="TEMP"): try: log = lib_Log.Log(PrintToConsole=True) log.increaseLevel() Value = {} temp = "" for line in cStringIO.StringIO(String): a = 0 while ((line[a:a + 1] == " ") or (line[a:a + 1] == "\t") or (line[a:a + 1]) == ":" or (line[a:a + 1]) == ">"): a = a + 1 line = line[a:] if (line[0:1] == "="): line = lib_Parsing.Get_Var_String(line) #ignore if modem session (iDirect) if (line[0:5] != "[RMT:"): temp = temp + line String = temp String = "[TEMP]" + "\n" + String buf = StringIO.StringIO(String) config = ConfigParser.ConfigParser() config.readfp(buf) for a in OriginalKeys: try: Value[a] = (config.get(Section, a)) except: Value[a] = None i = 0 end = len(OriginalKeys) Result = {} for keys in Value: Result[(ReplaceKeys[i])] = Value[OriginalKeys[i]] if Result[(ReplaceKeys[i])] is None: Result.pop(ReplaceKeys[i], None) log.printWarning( "%s Value was not found and have been removed" % ReplaceKeys[i]) i = i + 1 if i >= end: break return Result except Exception as e: #log.printError( str(e)) log.printWarning("Can not parse string : %s" % String) return None
def __init__(self, INI, deviceDescr, devNumber): self.Error = False self.log = lib_Log.Log(PrintToConsole=True) #for inhiretance from device class self.INI = INI self.deviceDescr = deviceDescr self.devNumber = devNumber self.log.increaseLevel() self.ipaddr = self.INI.getOption(self.deviceDescr, self.devNumber, "IP") self.getDataDict = { 'pduManufacturer': '1.3.6.1.4.1.13742.6.3.2.1.1.2.1', 'pduModel': '1.3.6.1.4.1.13742.6.3.2.1.1.3.1', 'pduSerialNumber': '1.3.6.1.4.1.13742.6.3.2.1.1.4.1', #'pduRatedVoltage' : '1.3.6.1.4.1.13742.6.3.2.1.1.5.1', #'pduRatedCurrent' : '1.3.6.1.4.1.13742.6.3.2.1.1.6.1', #'pduRatedFrequency' : '1.3.6.1.4.1.13742.6.3.2.1.1.7.1', #'pduRatedVA' : '1.3.6.1.4.1.13742.6.3.2.1.1.8.1', 'OutletCount': '1.3.6.1.4.1.13742.6.3.2.2.1.4.1', 'pduName': '1.3.6.1.4.1.13742.6.3.2.2.1.13.1', 'pduPower': '1.3.6.1.4.1.13742.6.5.2.3.1.6.1.1.5', 'pduVA': '1.3.6.1.4.1.13742.6.5.2.3.1.6.1.1.6', 'pduLineFrequency': '1.3.6.1.4.1.13742.6.5.2.3.1.6.1.1.23', 'pduMAC': '1.3.6.1.2.1.2.2.1.6.2', 'pduInletCurrent': '1.3.6.1.4.1.13742.6.5.2.3.1.6.1.1.1', 'pduInletVoltage': '1.3.6.1.4.1.13742.6.5.2.3.1.4.1.1.4', } #get number of outputs snmpDevice = lib_SNMP.SNMPv2(self.ipaddr) outletCount = snmpDevice.readSNMP(self.getDataDict['OutletCount']) #loop over outlets if outletCount is not None: for x in range(1, int(outletCount) + 1): self.getDataDict["outlet" + str(x)] = {} self.getDataDict["outlet" + str( x)]['name'] = '1.3.6.1.4.1.13742.6.3.5.3.1.3.1.' + str(x) self.getDataDict["outlet" + str( x )]['status'] = '1.3.6.1.4.1.13742.6.4.1.2.1.2.1.' + str( x ) #0 off, 1 on, 2 offWait, 3 onWait, 4 offError, 5 On Error, 6nocomm, 7 reading, 8 offFuse, 9 onFuse self.getDataDict["outlet" + str( x )]['uptime'] = '1.3.6.1.4.1.13742.6.4.1.2.1.4.1.' + str( x ) #0 idleOff, 1 idleOn, 2 wakeOff, 3 wakeOn, 4 off, 5 on, 6 lockedOff, 7 lockedOn, 8 reboot, 9 shutdown, 10 pendOn, 11 pendOff, 12 minimumOff, 13 minimumOn, 14 eventOff, 15 eventOn, 16 eventReboot, 17 eventShutdown
def __init__(self, INI, deviceDescr, devNumber): self.Error = False self.log = lib_Log.Log(PrintToConsole=True) #for inhiretance from device class self.INI = INI self.deviceDescr = deviceDescr self.devNumber = devNumber self.log.increaseLevel() #connection information self.IP = None self.modBusPort = None self.slaveID = None self.dictID = 1000
def __init__(self, INI, deviceDescr, devNumber): self.Error = False self.log = lib_Log.Log(PrintToConsole=True) #for inhiretance from device class self.INI = INI self.deviceDescr = deviceDescr self.devNumber = devNumber self.log.increaseLevel() self.ipaddr = self.INI.getOption(self.deviceDescr, self.devNumber, "IP") self.getDataDict = { # 'sysDescr' : '1.3.6.1.2.1.1.1.0', 'sysUpTime': '1.3.6.1.2.1.1.3.0', }
def __init__(self, INI, deviceDescr, devNumber): self.Error = False self.log = lib_Log.Log(PrintToConsole=True) #for inhiretance from device class self.INI = INI self.deviceDescr = deviceDescr self.devNumber = devNumber self.log.increaseLevel() self.ipaddr = self.INI.getOption(self.deviceDescr, self.devNumber, "IP") self.getDataDict = { 'systemDescription' : '1.3.6.1.2.1.1.1.0', 'systemUpTime' : '1.3.6.1.2.1.1.3.0', 'systemContact' : '1.3.6.1.2.1.1.4.0', 'systemName' : '1.3.6.1.2.1.1.5.0', 'systemLocation' : '1.3.6.1.2.1.1.6.0', 'systemVersion' : '1.3.6.1.4.1.1718.3.1.1.0', 'systemNICSerialNumber' : '1.3.6.1.4.1.1718.3.1.2.0', 'systemTotalPower' : '1.3.6.1.4.1.1718.3.1.6.0', 'infeedID' : '1.3.6.1.4.1.1718.3.2.2.1.2.1.1', 'infeedName' : '1.3.6.1.4.1.1718.3.2.2.1.3.1.1', 'infeedStatus' : '1.3.6.1.4.1.1718.3.2.2.1.5.1.1', #0 off, 1 on, 2 offWait, 3 onWait, 4 offError, 5 On Error, 6nocomm, 7 reading, 8 offFuse, 9 onFuse 'infeedLoadValue' : '1.3.6.1.4.1.1718.3.2.2.1.7.1.1', #in 1/100th of Amps 'infeedLoadHighThresh' : '1.3.6.1.4.1.1718.3.2.2.1.8.1.1', 'infeedOutletCount' : '1.3.6.1.4.1.1718.3.2.2.1.9.1.1', #number of outputs 'infeedCapacity' : '1.3.6.1.4.1.1718.3.2.2.1.10.1.1', 'infeedVoltage' : '1.3.6.1.4.1.1718.3.2.2.1.11.1.1', 'infeedPower' : '1.3.6.1.4.1.1718.3.2.2.1.12.1.1', 'towerStatus' : '1.3.6.1.4.1.1718.3.2.1.1.4.1', #0 normal, 1 noComm, 2, fanFail, 3 overTemp, 4 nvmfail, 5 outOfBalance 'towerProductSN' : '1.3.6.1.4.1.1718.3.2.1.1.6.1', 'towerModelNumber' : '1.3.6.1.4.1.1718.3.2.1.1.7.1', } #get number of outputs snmpDevice = lib_SNMP.SNMPv2(self.ipaddr) outletCount = snmpDevice.readSNMP(self.getDataDict['infeedOutletCount']) #loop over outlets if outletCount is not None: for x in range(1, int(outletCount) + 1): self.getDataDict["outlet" + str(x)] = {} self.getDataDict["outlet" + str(x)]['ID'] = '1.3.6.1.4.1.1718.3.2.3.1.2.1.1.' + str(x) self.getDataDict["outlet" + str(x)]['name'] = '1.3.6.1.4.1.1718.3.2.3.1.3.1.1.' + str(x) self.getDataDict["outlet" + str(x)]['status'] = '1.3.6.1.4.1.1718.3.2.3.1.5.1.1.' + str(x) #0 off, 1 on, 2 offWait, 3 onWait, 4 offError, 5 On Error, 6nocomm, 7 reading, 8 offFuse, 9 onFuse self.getDataDict["outlet" + str(x)]['controlState'] = '1.3.6.1.4.1.1718.3.2.3.1.10.1.1.' + str(x) #0 idleOff, 1 idleOn, 2 wakeOff, 3 wakeOn, 4 off, 5 on, 6 lockedOff, 7 lockedOn, 8 reboot, 9 shutdown, 10 pendOn, 11 pendOff, 12 minimumOff, 13 minimumOn, 14 eventOff, 15 eventOn, 16 eventReboot, 17 eventShutdown
def __init__(self, INI, deviceDescr, devNumber): self.Error = False self.log = lib_Log.Log(PrintToConsole=True) #for inhiretance from device class self.INI = INI self.deviceDescr = deviceDescr self.devNumber = devNumber self.log.increaseLevel() self.ipaddr = self.INI.getOption(self.deviceDescr, self.devNumber, "IP") Dictionary = self.INI.getOption(self.deviceDescr, self.devNumber) self.getDataDict = {} for Name in Dictionary: if Name.startswith('GET_'): self.getDataDict[Name[4:]] = Dictionary[Name]
def __init__(self, INI, Section, MailDestination="Internal"): self.log = lib_Log.Log(PrintToConsole=True) self.log.subTitle("START Mail Program") self.INI = INI self.SmtpPort = 587 # self.Smtp = "webmail.imtechmarine.com" # self.fromaddr = "*****@*****.**" # self.Username = "******" # self.Password = "******" self.Smtp = "smtp.gmail.com" self.fromaddr = "*****@*****.**" self.Username = "******" self.Password = "******" # # self.Smtp = "10.2.86.117" # self.Smtp = "webmail.imtechmarine.com" # self.Username = '******' # self.Password = "******" # self.fromaddr = "*****@*****.**" MailEnable = self.INI.getOptionBool(Section, "MAILENABLE") if MailEnable == None or MailEnable == False: self.log.printWarning("Sending mail in '%s' is not enabled" % Section) return if MailDestination.lower() == "internal": Mailnumbers = self.INI.getOption(Section, "MAIL") elif MailDestination.lower() == "external": Mailnumbers = self.INI.getOption(Section, "MAILEXTERNAL") if Mailnumbers is None: self.log.printWarning( "No %s mailaddresses for '%s' are configured" % (MailDestination.lower(), Section)) return self.toaddr = [] for Mailnumber in Mailnumbers: Mail = self.INI.getOptionStr(Section, "MAIL", Mailnumber) if Mail != None: self.toaddr.append(Mail) self.msg = MIMEMultipart() self.msg['From'] = self.fromaddr self.msg['To'] = ", ".join(self.toaddr)
def __init__(self, INI, deviceDescr, devNumber): self.Error = False self.log = lib_Log.Log(PrintToConsole=True) #for inhiretance from device class self.INI = INI self.deviceDescr = deviceDescr self.devNumber = devNumber self.log.increaseLevel() self.ipaddr = self.INI.getOption(self.deviceDescr, self.devNumber, "IP") self.getDataDict = { #'sysDescr' : '1.3.6.1.2.1.1.1.0', 'sysUpTime': '1.3.6.1.2.1.1.3.0', #'sysContact' : '1.3.6.1.2.1.1.4.0', 'sysName': '1.3.6.1.2.1.1.5.0', #'sysLocation' : '1.3.6.1.2.1.1.6.0', 'outletCount': '1.3.6.1.4.1.318.1.1.12.1.8.0', #'1.3.6.1.4.1.318.1.1.4.5.1.0', #Num of Outputs 'loadStatusCurrent': '1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1', #phase/bank load measured in tenths of Amps 'HardwareRev': '1.3.6.1.4.1.318.1.1.12.1.2.0', 'FirmwareRev': '1.3.6.1.4.1.318.1.1.12.1.3.0', 'DateOfManufacture': '1.3.6.1.4.1.318.1.1.12.1.4.0', 'ModelNumber': '1.3.6.1.4.1.318.1.1.12.1.5.0', 'SerialNumber': '1.3.6.1.4.1.318.1.1.12.1.6.0', 'DeviceRating': '1.3.6.1.4.1.318.1.1.12.1.7.0', #max amps 'SerialNumber': '1.3.6.1.4.1.318.1.1.12.1.6.0', 'DevicePowerWatts': '1.3.6.1.4.1.318.1.1.12.1.16.0', 'DevicePowerVA': '1.3.6.1.4.1.318.1.1.12.1.18.0', } #get number of outputs snmpDevice = lib_SNMP.SNMPv2(self.ipaddr) outletCount = snmpDevice.readSNMP(self.getDataDict['outletCount']) #loop over outlets if outletCount is not None: for x in range(1, int(outletCount) + 1): self.getDataDict["outlet" + str(x)] = {} # self.getDataDict["outlet" + str(x)]['ID'] = '1.3.6.1.4.1.1718.3.2.3.1.2.1.1.' + str(x) self.getDataDict["outlet" + str( x)]['name'] = '1.3.6.1.4.1.318.1.1.12.3.5.1.1.2.' + str(x) self.getDataDict["outlet" + str(x)][ 'status'] = '1.3.6.1.4.1.318.1.1.12.3.5.1.1.4.' + str(x) #
def __init__(self, INI): """ini GIT object""" # self.Error = False # self.log = lib_Log.Log(PrintToConsole=True) # self.INI = INI # cwd = os.getcwd() # self.GITDir = {"PYTHON" : cwd, "WEB" : "/rhbox/www/web/"} self.INI = INI self.vessel_number = INI.getOption("INFO","IMO") config_data = lib_config.CONFIG_DATA() # COUCH DATABASE NAME self.couchdb_name = config_data.couchdb_name # COUCH CREDENTIALS self.couch_protocol = config_data.couch_protocol self.couch_user = config_data.couch_user self.couch_password = config_data.couch_password self.couch_host = config_data.couch_host self.couch_port = config_data.couch_port self.remote_couch_protocol = config_data.remote_couch_protocol self.remote_couch_user = config_data.remote_couch_user self.remote_couch_password = config_data.remote_couch_password self.remote_couch_host = config_data.remote_couch_host self.remote_couch_port = config_data.remote_couch_port self.remote_db_name = config_data.remote_db_name self.backend_dir = config_data.backend_dir self.api_dir = config_data.api_dir self.web_dir = config_data.web_dir self.web_branch = config_data.web_branch self.api_branch = config_data.api_branch self.backend_branch = config_data.backend_branch self.log = lib_Log.Log(PrintToConsole = True)
def __init__(self, INI, deviceDescr, devNumber): self.Error = False self.log = lib_Log.Log(PrintToConsole=True) #for inhiretance from device class self.INI = INI self.deviceDescr = deviceDescr self.devNumber = devNumber self.log.increaseLevel() self.ipaddr = self.INI.getOption(self.deviceDescr, self.devNumber, "IP") self.snmpPort = self.INI.getOption(self.deviceDescr, self.devNumber, "SNMPPORT") self.snmpPort = 161 if self.snmpPort is None else self.snmpPort self.community = self.INI.getOption(self.deviceDescr, self.devNumber, "SNMPCOMMUNITY") self.community = 'public' if self.community is None else self.community #snmpDevice = lib_SNMP.SNMPv2(self.ipaddr) #outletCount = snmpDevice.readSNMP(self.getDataDict['OutletCount']) """
def __init__(self, INI, Policy=None): """ Init vars Initial check """ #general vars self.log = lib_Log.Log(PrintToConsole=True) self.INI = INI self.Error = False self.ForceAll = False self.syncTables = {} self.Policy = Policy #get dbName self.imoNumber = self.INI.getOptionStr("INFO", "IMO") # self.dbName = "rhbox_" + self.imoNumber self.dbName = "rhdev_" + self.imoNumber #get server credentials self.DB_Remote_Host = self.INI.getOptionStr("DB_RHBOX_SERVER", "HOST") self.DB_Remote_User = self.INI.getOptionStr("DB_RHBOX_SERVER", "USER") self.DB_Remote_Password = self.INI.getOptionStr( "DB_RHBOX_SERVER", "PASSWORD") self.DB_Remote = lib_SQLdb.Database() #get localhost credentials self.DB_Local_Host = self.INI.getOptionStr("DB_LOCAL", "HOST") self.DB_Local_User = self.INI.getOptionStr("DB_LOCAL", "USER") self.DB_Local_Password = self.INI.getOptionStr("DB_LOCAL", "PASSWORD") self.DB_Local = lib_SQLdb.Database() #check vars if None in (self.imoNumber, self.DB_Remote_Host, self.DB_Remote_User, self.DB_Remote_Password, self.DB_Local_Host, self.DB_Local_Password): self.Error = True self.log.printError( "User, Host or Password not defined for local or remote SQL-server" )
def String_WithSection_Parse(String, device, parameters): log = lib_Log.Log(PrintToConsole=True) buf = StringIO.StringIO(String) Config = ConfigParser.ConfigParser() Config.readfp(buf) try: returnValue = {} #if Info# unqiueSection = False if "#" in device: device = device.replace("#", "") regex = "^" + device + '$' unqiueSection = True else: regex = "^" + device + '[0-9]+$' #loop over ini files for confFile in Config: #loop over sections for section in Config[confFile].sections(): #filter out non-valid sections #str matches - e.g. Switch1 if re.match(regex.lower(), section.lower()): #get number of device #section = Switch1, Switch2, ... if unqiueSection: number = -1 else: number = int(section.replace(device, "")) returnValue[number] = {} #loop over parameters for var in parameters: subParameters = parameters[var] key = subParameters['key'].lower() type = subParameters['type'].lower() if Config[confFile].has_option(section, key): if (type == "str"): returnValue[number][var] = Config[ confFile].get(section, key) elif (type == "int"): returnValue[number][var] = Config[ confFile].getint(section, key) elif (type == "float"): returnValue[number][var] = Config[ confFile].getfloot(section, key) elif (type == "bool"): returnValue[number][var] = Config[ confFile].getboolean(section, key) else: returnValue[number][var] = Config[ confFile].get(section, key) #check if all parameters are defined for each device for deviceNumber in returnValue: returnValue[deviceNumber]["Error"] = False for var in parameters: if var in returnValue[deviceNumber]: pass else: msg = "Warning: " + var + " not defined for " + device if (deviceNumber == -1): msg += str(deviceNumber) self.log.printError(msg) returnValue[deviceNumber]["Error"] = True if (deviceNumber == -1): returnValue = returnValue[-1] break except: self.log.printError("%s Module Error" % sys._getframe().f_code.co_name) returnValue = False return returnValue
def __init__(self, **kwargs): self.log = lib_Log.Log(PrintToConsole=True) #init vars self.noErrors = True self.socket = None # CONFIG self.config_data = lib_config.CONFIG_DATA() #get arguments self.INI = kwargs.pop('INI', None) self.sendHost = kwargs.pop('sendHost', None) self.interface = kwargs.pop('interface', self.config_data.interface) self.sendPort = kwargs.pop('sendPort', None) self.receiveBuffer = kwargs.pop('receiveBuffer', 1024) self.bindHost = kwargs.pop('bindHost', '') self.bindPort = kwargs.pop( 'bindPort', self.sendPort) #default the same as sendPort self.timeOut = kwargs.pop('timeOut', 3) self.socketType = kwargs.pop('socketType', "UDP") #set bindAddress self.bindAddress = None if self.bindPort is not None: try: self.bindAddress = (self.bindHost, int(self.bindPort)) except: self.log.printError( "Error during setting socketUDP-bind adress, host = %s, port = %s (should be numeric)" % (self.bindHost, self.bindPort)) self.noErrors = False else: self.noErrors = False if self.noErrors: try: if self.socketType == "TCP": self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) else: #UDP or Broadcast self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) #special treatment for multicast adresses if lib_IP.CheckIfIPIsMulticastAddress(self.bindHost): network = Class_NetworkConfig.NetworkConfig( self.INI, "none") network.AddRoute(self.bindHost, "255.255.255.255", self.interface) self.socket.bind(('', int(self.bindPort))) group = socket.inet_aton(self.bindHost) mreq = struct.pack('4sL', group, socket.INADDR_ANY) self.socket.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq) else: self.socket.bind(self.bindAddress) self.socket.setblocking(0) return except Exception as e: self.noErrors = False return return
def __init__(self, INI, GitVersions): self.Error = False self.log = lib_Log.Log(PrintToConsole=True) self.INI = INI self.GitVersions = GitVersions self.RebootDisable = False
def __init__(self, INI): self.log = lib_Log.Log(PrintToConsole=True) self.Error = False self.INI = INI