Guests running on ESX

(imported topic written by jcsUTSW)

I realize this isn’t groundbreaking tricky relevance but it’s something I’ve wanted to do for a while.

I wanted to have all the guests that are currently running on an ESX host in my BigFix data.

There’s probably a better / cleaner way of doing it but this is what I came up with…

First I created a task… I can put this on a policy and run X often.

Relevance1

name of operating system as lowercase contains “vmware”

Action1

// enter your action script here

wait rm -rf “…/…/guests.txt”

wait bash -c "vmware-cmd -l &> ‘…/…/guests.txt’ "

Then I created an analysis that looks like this…

Relevance1

name of operating system as lowercase contains “vmware” and exists file “/var/opt/BESClient/guests.txt”

Property (name it whatever you want)

following texts of lasts “/” of preceding texts of lasts “.vmx” of lines of file “/var/opt/BESClient/guests.txt”

What the above does is give me the list of machine names that are currently running on that host.

Maybe this is something you can use.

Enjoy

(imported comment written by SystemAdmin)

Expanding on this, I would like to get more information like “getstate” or “hassnapshot”

root@esxhost bin

vmware-cmd -l | xargs -t -i vmware-cmd {} getstate

vmware-cmd /vmfs/volumes/4787c3d2-24c09f7a-03b4-001cc4de5b82/server1/server1.vmx getstate

getstate() = on

vmware-cmd /vmfs/volumes/4787c3d2-24c09f7a-03b4-001cc4de5b82/server2/server2.vmx getstate

getstate() = on

vmware-cmd /vmfs/volumes/48b6f75f-068b572b-639a-001cc4de5b82/server3-temp/server3-temp.vmx getstate

getstate() = off

vmware-cmd /vmfs/volumes/4787c3d2-24c09f7a-03b4-001cc4de5b82/server4/server4.vmx getstate

getstate() = on

so my question is

Property (name it whatever you want)

following texts of lasts “/” of preceding texts of lasts “.vmx” of lines of file “/var/opt/BESClient/guests.txt”

how would I use the property above and then append the next line below it to the end or something like that

so the output would be

server1 - on
server2 - on
server3-temp - off
server4 - on

(imported comment written by BenKus)

This looks like very useful info… thanks guys…

This revision might help:

q: (following text of last “/” of preceding text of first “.vmx” of it, following text of last "= " of next line of it) of lines whose (it contains “vmx”) of file "C:\temp\temp.txt"
A: server1, on
A: server2, on
A: server3-temp, off
A: server4, on

Ben

(imported comment written by SystemAdmin)

Thank You Ben…

Here’s the rest of it

Task Action1

wait rm -rf “/var/opt/BESClient/getstate.txt”

wait rm -rf “/var/opt/BESClient/hassnapshot.txt”

wait bash -c “vmware-cmd -l | xargs -t -i vmware-cmd {{} getstate &> ‘/var/opt/BESClient/getstate.txt’”

wait bash -c “vmware-cmd -l | xargs -t -i vmware-cmd {{} hassnapshot &> ‘/var/opt/BESClient/hassnapshot.txt’”

Relevance1

name of operating system as lowercase contains “vmware” and exists file “/var/opt/BESClient/getstate.txt”

Analysis:

Title: Virtual Guest and State Info (getstate)

(following text of last “/” of preceding text of first “.vmx” of it as uppercase& " - " & following text of last "= " of next line of it as uppercase) of lines whose (it contains “vmx”) of file “/var/opt/BESClient/getstate.txt”

Title: Virtual Guest and Snapshot Info (hassnapshot)

(following text of last “/” of preceding text of first “.vmx” of it as uppercase& " - " & following text of last "= " of next line of it as uppercase) of lines whose (it contains “vmx”) of file “/var/opt/BESClient/hassnapshot.txt”

(imported comment written by anthonymap91)

This worked very well for a report I needed, but how would I make this a policy action? So it updates once or twice per day.

Thanks,

anthony

(imported comment written by anthonymap91)

I got a note that someone replied, but the link did not work.

Please reply again thanks.

anthony

(imported comment written by SystemAdmin)

You could create a automatic computer group with a policy action that would run every time a computer becomes relevant to it and set the timing on the group

Below, this way every 12 hours it would become relevant, it would check the file time and re run it twice a day

it will also run if the file does not exist

Automatic Computer Group Relevance 2 times per day

(name of operating system as lowercase contains “esx”) and (not exists file “/var/opt/BESClient/getstate.txt”) or ((modification time of file “/var/opt/BESClient/getstate.txt”) < (now - 12 * hour))

Automatic Computer Group Relevance 1 times per day

(name of operating system as lowercase contains “esx”) and (not exists file “/var/opt/BESClient/getstate.txt”) or ((modification time of file “/var/opt/BESClient/getstate.txt”) < (now - 1 * day))

I do the same thing with DMIDecode Information, I refresh this every week

(version of client >= “6.0.0.0”) and (true and exists true whose (if true then (((name of operating system as lowercase contains “linux”) or (name of operating system as lowercase contains “esx”)) and ((not exists file “/root/dmidecode.out”) or ((modification time of file “/root/dmidecode.out”) < (now - 7 * day)))) else false))