mail
command) you will need to install the mailutils package. And many system administrators will not want to create a potential vulnerability in their production server in the form of a service that can send letters anywhere. Yes, and the opportunity may not be due to the closeness of the ports, the independence of subnets and so on ...veeamconfig
command with veeamconfig
. The veeamconfig
team provides access to all product functionality. Undoubtedly, the pseudo-graphic interface created using the ncurses library is much more pleasant for the eyes, but if you want to link programs to something new, then CLI is our everything.veeamconfig --help
and you will get a list of available commands: $sudo veeamconfig --help Veeam Agent for Linux (c) Veeam Software AG Usage: veeamconfig [command] Commands: repository - Backup repositories management vbrserver - Veeam Backup and Replication servers management job - Backup jobs management backup - Backups management point - Restore points management license - License management agreement - End User License Agreement management config - Import/export configuration schedule - Jobs schedule configuration cloud - Cloud provider management mode - Operation mode session - Sessions management ui - User interface aap - Application-aware processing version, --version, -v - Product version help, --help, -h - Short help
veeamconfig config --help
. We get: Veeam Agent for Linux (c) Veeam Software AG Usage: veeamconfig config [command] Commands: import - Import repositories and jobs into database export - Export repositories and jobs from database grabLogs - Collect support logs bundle patchiso - Create custom Veeam Recovery Media adding all hardware drivers from this system help, --help, -h - Short help
grabLogs
log collection grabLogs
. It allows you to quickly collect all the necessary logs for support. This is in case something goes wrong. $ sudo veeamconfig agreement --help Veeam Agent for Linux (c) Veeam Software AG Usage: veeamconfig agreement [command] Commands: acceptEula - Accept Veeam End User License Agreements acceptThirdPartyLicenses - Accept Veeam 3rd party License Agreement show - Show End User License Agreements acceptance status help, --help, -h - Short help
$ sudo veeamconfig job list I accept Veeam Software End User License Agreement: /usr/share/doc/veeam/EULA (yes/no | y/n): yes I accept the terms of the following 3rd party software components license agreements: /usr/share/doc/veeam/3rd_party (yes/no | y/n):
veeamconfig agreement acceptEula veeamconfig agreement acceptThirdPartyLicenses
veeamconfig session list
. It displays something like: Job name Type ID State Started at Finished at bj-home Backup {dbe48e88-3df7-4712-a472-09af8fed4e80} Success 2018-12-05 15:43 2018-12-05 15:44 bj-home Backup {c178a799-2935-4bd6-883b-b11278000076} Success 2018-12-05 16:26 2018-12-05 16:26 bj-home Backup {3405dad3-0016-4a00-933e-60ef66b30324} Success 2018-12-06 06:00 2018-12-06 06:00
class CSession: @staticmethod def List(): return subproccall( ["veeamconfig", "session", "list"] ) class CSessionInfoList(object): def __init__(self, list): self.list = list def List(self): return self.list @staticmethod def Get(): text = CSession.List() lines = text.split("\n") list = [] # session info list for line in lines: if len(line) == 0: continue words = line.split() if len(words) == 0: continue if words[0] == "Job": continue if words[0] == "Total": continue try: jobName = words[0] type = words[1] id = words[2] state = words[3] startTime = words[4] + " " + words[5] finishTime = words[6] + " " + words[7] list.append(CSessionInfo(id, type, jobName, state, startTime, finishTime)) except: print "Failed to parse [", line, "]" return CSessionInfoList(list)
def SendMailsessions(): print "---" print "Sending statistic to administrator:" sessions = veeamlpb.session.CSessionInfoList.Get() recipient = "dear.admin@company.com" subject = "VAL status notification" text = "Statistic:\n" inx = 0; successCount = 0 warningCount = 0 errorCount = 0 for sessionInfo in sessions.List(): if (sessionInfo.State() == "Success"): successCount += 1 elif (sessionInfo.State() == "Warning"): warningCount += 1 else: errorCount += 1 text += str(successCount)+"/"+str(warningCount)+"/"+str(errorCount)+" Success/Warning/Error\n" text += "Last 10 session:\n" for sessionInfo in reversed(sessions.List()): if inx == 10: text += "...\n" break; text += str(inx)+" | "+sessionInfo.State()+" | "+sessionInfo.JobName()+" | "+sessionInfo.StartTime()+" / "+sessionInfo.FinishTime() + "\n" #text += inx += 1 text += "\n" text += "--------------------------------------------------------------------------------\n" text += " Yours sincerely, Veeam Agent for Linux Monitor\n" print text os.system("echo '"+text+"' | mail -s '"+subject+"' "+recipient)
Statistic: 3/0/0 Success/Warning/Error Last 10 session: 0 | Success | bj-home | 2018-12-06 06:00 / 2018-12-06 06:00 1 | Success | bj-home | 2018-12-05 16:26 / 2018-12-05 16:26 2 | Success | bj-home | 2018-12-05 15:43 / 2018-12-05 15:44 -------------------------------------------------------------------------------- Yours sincerely, Veeam Agent for Linux Monitor
sessionList = veeamlpb.session.CSessionList() text = sessionList.ToXml()
sessionListFileName = "session_list.xml" print "Store XML to file: ",sessionListFileName sessionListXmlFile = open(sessionListFileName, "w") sessionListXmlFile.write(text) sessionListXmlFile.close()
hostname = os.uname()[1] target = "user@admin-desktop:/home/user" os.system("scp ./"+sessionListFileName+" "+target+"/backups/"+hostname+"/session_list.xml")
import veeamlpb import os import datetime import xml.etree.ElementTree as xml def main(): hosts = [] backupsDirectory = "/home/user/backups" for item in os.listdir(backupsDirectory): if item in [".", ".."]: continue if os.path.isdir(os.path.join(backupsDirectory,item)): hosts.append(item) print "item: ",item if len(hosts) == 0: return 0 backupSessionMap = {} for host in hosts: print "found host: ", host sessionInfoFile = os.path.join(os.path.join(backupsDirectory,host), "session_list.xml") sessionList = veeamlpb.session.CSessionInfoList.FromXmlFile(sessionInfoFile) backupSessionMap[host] = sessionList for sessionInfo in sessionList.List(): print "Session:",sessionInfo.ToString() html = xml.Element("html") body = xml.SubElement(html, "body", {"style":"background-color: #00b336;"}) xml.SubElement(body,"h1").text = "Report at "+datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") xml.SubElement(body,"h2").text = "Statistic:" for host in hosts: sessionList = backupSessionMap[host] success=0 warning=0 error=0 if len(sessionList.List()) == 0: continue for sessionInfo in sessionList.List(): if sessionInfo.State() == "Success": success +=1 elif sessionInfo.State() == "Warning": warning +=1 else: error +=1 latestSessionInfo = sessionList.List()[-1] attr = {} if latestSessionInfo.State() == "Success": #attr["style"] = "background-color: #00b336;" attr["style"] = "background-color: #005f4b; color: white;" elif latestSessionInfo.State() == "Warning": attr["style"] = "background-color: #93ea20;" else: attr["style"] = "background-color: #ba0200; color: white;" xml.SubElement(xml.SubElement(body,"p"),"span", attr).text = \ host + " - "+str(success)+"/"+str(warning)+"/"+str(error)+" Success/Warning/Error" for host in hosts: sessionList = backupSessionMap[host] xml.SubElement(body,"h2").text = host+":" tableStyle =xml.SubElement(body,"style") tableStyle.attrib["type"] = "text/css" tableStyle.text = "TABLE {border: 1px solid green;} TD{ border: 1px solid green; padding: 4px;}" table = xml.SubElement(body,"table") thead = xml.SubElement(table, "thead") xml.SubElement(thead, "th").text = "Number" xml.SubElement(thead, "th").text = "State" xml.SubElement(thead, "th").text = "Job name" xml.SubElement(thead, "th").text = "Start at" xml.SubElement(thead, "th").text = "Complete at" tbody = xml.SubElement(table, "tbody") inx = 0 for sessionInfo in reversed(sessionList.List()): if inx == 10: break; tr = xml.SubElement(tbody,"tr") xml.SubElement(tr, "td").text = str(inx) attr ={} if sessionInfo.State() == "Success": pass elif sessionInfo.State() == "Warning": attr["style"] ="background-color: #93ea20;" else: attr["style"] ="background-color: #ba0200; color: white;" xml.SubElement(tr, "td", attr).text = sessionInfo.State() xml.SubElement(tr, "td").text = sessionInfo.JobName() xml.SubElement(tr, "td").text = sessionInfo.StartTime() xml.SubElement(tr, "td").text = sessionInfo.FinishTime() inx += 1 xml.ElementTree(html).write("summary.html", encoding='utf-8', method='html') return 0 exit(main())
Source: https://habr.com/ru/post/432404/
All Articles