def createRrdSymLink(): try: if not os.path.exists(comLib.getSupportFilePath("RrdServ")): comLib.cmd("ln -s {}/{}/ {}".format( comLib.getSupportFilePath("RrdLib"), sysLib.getHostname(), comLib.getSupportFilePath("RrdServ"))) except Exception as e: print("Error Creating rrd symlink: {}".format(e))
def setIps(ipAddrs): for interface in ipAddrs: bringInterfaceDown(interface) time.sleep(1) for interface in ipAddrs: setInterfaceIp(interface, ipAddrs[interface]) time.sleep(1) for interface in ipAddrs: bringInterfaceUp(interface) time.sleep(1) comLib.cmd("sudo dhclient")
def enablePythonRrd(): cPath = comLib.getSupportFilePath("CollectdConf") startIndex = -1 stopIndex = -1 lastBlankSpace = -1 cLines = [x.rstrip() for x in open(cPath, 'r').readlines()] for x in range(len(cLines)): if re.match('^# ARMORE', cLines[x]) and startIndex == -1: startIndex = x elif re.match('^# ARMORE', cLines[x]) and startIndex != -1: stopIndex = x elif re.match('^$', cLines[x]) and startIndex == -1: lastBlankSpace = x newTxt = '''# ARMORE <LoadPlugin python> Globals true Interval 900 </LoadPlugin> <Plugin python> ModulePath "/var/webServer/domains/support" LogTraces true Interactive false import rrdDataParser <Module rrdDataParser> </Module> </Plugin> # ARMORE'''.split('\n') if startIndex == -1: cLines.extend(newTxt) else: cLines[startIndex:stopIndex + 1] = newTxt with open(cPath, 'w') as cFile: cFile.write("\n".join(cLines)) comLib.cmd("/etc/init.d/collectd restart")
def setInterfaceIp(interface, ip): theCmd = "sudo ip addr add {0} dev {1}".format(ip, interface) comLib.cmd(theCmd)
def bringInterfaceUp(interface): theCmd = "sudo ip link set {0} up".format(interface) comLib.cmd(theCmd)
def bringInterfaceDown(interface): theCmd = "sudo ip link set {0} down".format(interface) comLib.cmd(theCmd) clearIpsOfInterface(interface)
def clearIpsOfInterface(interface): theCmd = "sudo ip addr flush dev {0}".format(interface) comLib.cmd(theCmd)
def restartBro(): comLib.cmd('broctl restart')
def restartProxy(): comLib.cmd('/etc/init.d/armoreconfig stop') comLib.cmd('/etc/init.d/armoreconfig start')
def createArmoreDb(): try: comLib.cmd("sh {}".format(comLib.getSupportFilePath("ArmoreDBInit"))) except Exception as e: print("Error Creating armore.db: {}".format(e))