Forum Discussion

Maverick's avatar
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 download.

3 Replies

  • 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}
    }
  • Thanks Stuart….don’t necessarily need to open the TAR ball, just need to be able to capture it and download. I suspect change detection would be useful. The file is needed upon rebuild of an ESXi host.

  • If you don’t need to be able to read it, then just add println(zipContents) after zipContents is defined. You might also need to do something other than .getText() on the URL object. That’ll convert it to text, which might not be great since it’s probably more accurately a byte stream. 

    The diff engine should be able to tell you if it’s changed, but with it being compressed, you won’t really be able to see what it is that changed and you won’t be able to tell the diff engine to ignore certain lines that might always change.