Using tags from vsphere

i created a issue on github a while ago about using tags assigned in Vsphere to VM’s to be able to exclude certain vm’s from being monitored:

it seems that only the custom attributed are being stored in the DB.
currently we are importing only running vm’s to be monitored in icinga:

SELECT o.object_name,
vc.guest_ip_address, vc.hardware_numcpu, vc.hardware_memorymb FROM object
AS o
INNER JOIN virtual_machine AS vc ON o.uuid = vc.uuid
WHERE IS_IPV4(vc.guest_ip_address) and vc.guest_state LIKE 'running'

we also want to exclude certain running vm’s from being monitored. we are already using tags for assigning backup policy’s etc so we want to use the same system to exclude VM’s from the monitoring.

does anybody know of a way to do this?
Can someone let me know if the tags are stored in the DB somewhere or if this feature can be added?

using the vspheredb module version 1.1.0

Tags are not captured (yet) by vspheredb but custom attributes are. I use this SQL to capture VM details:

SELECT vm.instance_uuid, o.object_name, vc.name, vc.product_line, vm.custom_values, vm.guest_ip_address, vm.guest_id
FROM object as o 
LEFT JOIN vcenter AS vc ON o.vcenter_uuid = vc.instance_uuid 
LEFT JOIN virtual_machine AS vm ON o.uuid = vm.uuid
WHERE o.object_type = 'VirtualMachine'
ORDER BY o.object_name 

I prefer to get all the results and then filter later. I have rather a lot of vCentres and ESXi hosts to grab data from, so I use instance_uuid as the hostname for VMs to guarantee uniqueness.

I create a custom attribute called Monitoring and fill it with a string I am interested in for the site or whatever.

custom_values comes in as a JSON array that can be modified with “Decode a JSON string” into another column - I call mine cv. Then you can extract the field cv.Monitoring into another column - I add a modifier called cv.Monitoring and use the uppercase modifier on it to ensure it is in the right format. I then Combine multiple properties to set display_name to ${Monitoring}-${object_name} .

With this lot I get a host in Icing named after the UUID with a display_name of the site and the hostname combined.

Sadly this only works on vCentres. I’m still thinking about how to deal with individual esxis without vCentres, which don’t get custom_attributes. lol

(I know this is an old post but it may help someone)

1 Like

Hello Jon,

As a beginner, I’ve tried to replicate your setup and I reached the point where I was able to create the modifier to decode the JSON string of my custom_values and retrieve the good field.
What I’m missing now is what to do with this attribute to :

  • still ensure the VM gets included in Icinga
  • but its monitoring is DISABLED

May you give me a hint, please?

Nicolas

That post was two years ago! Let me have a think about this …

Cheers
Jon

vspheredb now captures tags. See the change log (v1.6) I’m updating mine now …

Maybe use it to decide on which host template to import and use a template with notification disabled?

Hello,

That may look ugly, but I managed to reach my desired situation by stacking three modifiers :

  • one (“Decode a JSON string”) to parse the json coming from the vSphere VM notes (and to retrieve the desired note field)
  • one (“Replace null value with string”) to make sure that the null value never appears anytime. I’m replacing it with “false”
  • one (“Convert to a boolean value”) to convert to “true” if it’s true/TRUE/True/etc… or “false” if it’s anything else

then I’m using this last value to update the “disabled” field in the sync rules properties.

Not bad for a beginner :slight_smile:

Actually, I’d rather find a more straightforward way, but still keep using the notes. Tags may be cool but not relevant in our company.

1 Like