Assign a tags value to a variable - how?

Hello,

I’m collecting data using the vsphere plugin running from a central server.

This plugin collects the host name, which in this case is the central server running this plugin has “host”, “esxhost” and “vm_name”

The “host” name is the name of the central server running telegraf, which isn’t too meaningful in our alerts

When an alert is created, we send the data to an API (we’re using MS automate) we get the alert payload which contains both values. I want to get the tag value for “esxhost” or “vmname” and assign it to a new variable “host_actual”

i then want to use this variable to create a new tag that is sent to my API so we get “host: host_actual” - This would have the value of either the esxhost or the vm being monitored but means we would have consistent tag name in our workflow.

I’m struggling to do this though, I’ve declared a new variable in my script

var host_actual = '{{index .Tags "esxhost}}

I then pass this to a lambda expression to convert it to a string and save it as a tag.
image

The problem I’m having at the moment is no matter how i try to evaluate host_actual i either get

  1. {{index .Tags “esxhost”}}
    OR
    simply the value “host_actual”

I’ve tried single/double quotes. no quotes, I’ve added a |default node to try and do this but i get the same values as above which makes me think that its a problem with the variable?

Now, i KNOW i can add .tag() to the end of my influxDBOut node which should insert the tag value into my database (though i think at the moment i might end up with the same result), however i don’t want to keep this tag in my data. Its sole purpose is being sent to the API.

Unfortunately the JSON parser in MS automate isn’t as smart as we’d like, the only way we’ve found to get the data in there without really complex work flows is to convert the fields to tags, send them to the API and then drop the new tags before being written to a database.

Any idea how i can do this?

PhilB

Edit: the fields we are converting to tags is working fine, its just this one

Hello @philb,
I’m not the best at TICK script, but I believe you want to use sideload. Please take a look.

Hi @Anaisdg thank you for responding.

As it happens, i was over thinking this. We have a custom solution for managing our templates, when we create an alert we apply a group of hosts to the alert. This is fed to a string variable in the templates (host) and passed to the whereFilter. This value is always a VM or physical host

var host string
var whereFilter = lambda: (isPresent("host_name") AND "host_name" == host OR isPresent("vm_name") AND "vm_name" == host)

This way, it doesn’t matter too much what the host tag key is (host, esxhost, host_name) as long as the value for ‘host’ matches a value for one of those tags I can do what i need to.

The sideload node does look interesting though. I think i can use that to manage maintainance windows as per the documentation which would be useful.

Thank you :slight_smile:

1 Like

@philb,
Sure thing! Thank you for sharing your solution!

1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.