2 years ago
VMware ESXi Host configuration
Is it possible to capture the ESXi host configuration backup using LogicMonitor. It’s two commands # vim-cmd hostsvc/firmware/sync_config # vim-cmd hostsvc/firmware/backup_config and then a downlo...
Oh, i see: after issuing the command, the response is the url. You then need to use that URL to download the file, uncompress it, and view it.
This will get you close. However, my Groovy-foo is weak when it comes to decompression targz files. Maybe someone can chime in with more. Maybe I could write it to file and use one of the java methods to unzip it.
Create a ConfigSource. Make it multi-instance. The discovery script would look like this:
println("sync_config##sync_config")
println("backup_config##backup_config")
return 0
You could sexy this up by making it read the list of commands from a property on the file, but this is simplest.
Then your collection script would look like this. zipContents needs to be unzipped and printed to stdout.
import com.santaba.agent.groovyapi.expect.Expect
def hostname = hostProps.get("system.hostname")
def userid = hostProps.get("ssh.user")
def passwd = hostProps.get("ssh.pass")
def wildvalue = (instanceProps) ? instanceProps.wildvalue.toLowerCase() : "##WILDVALUE##"
prompt = "]"
try {
def ssh_connection = Expect.open(hostname, userid, passwd)
ssh_connection.expect(prompt)
ssh_connection.send("vim-cmd hostsvc/firmware/${wildvalue}\n")
ssh_connection.expect(prompt)
cmd_output = ssh_connection.before()
ssh_connection.send("exit\n")
ssh_connection.expectClose()
target = ""
prefix = ""
cmd_output.eachLine{
if (it.contains("Bundle can be downloaded")){
prefix = it.tokenize(": ")[-2]
target = it.tokenize(": ")[-1].replaceAll(/\*/,hostname)
}
}
if (target){
zipContents = new URL(prefix + ":" + target).getText()
}
return 0
} catch (Exception e) {println e;return 1
} finally {
try {
ssh_connection.expectClose()
} catch (Exception e) {return 0}
}