VMware Cloud Community
sxnxr
Commander
Commander
Jump to solution

alerts to a shim server

I am not sure if this is the correct place but couldn't find a better place

We send our alerts using REST top a shim server that transform the payload into a format out upstream service can read. this is an example

payload = {

     "eventId": " VMWare ",

        "body": {

            "serverName": a['resourceName'].replace('ourdomain.com',''),

            "AlertMessage": a['info'],

            "EventInstance": a['subType'],

            "Criticality": a['criticality'],

            "EventName": a['AlertName'],

            "EventType": a['type'],

            "EventSubType": a['subType'],

            "type": "link",

            "url": a['url'],

Our ESXi hosts are connected using the FQDN and the replace in the above removed the domain name because our upstream service used the short name. It also changes vrops field names to what we need.

We recently started to deploy vsan the resource name (triggered on) is now vSAN Cluster(cluster name)

What i need to do is remove all text and leave cluster name. Any help would be great. If it needs to be a new endpoint that is fine

0 Kudos
1 Solution

Accepted Solutions
dtaliafe
Hot Shot
Hot Shot
Jump to solution

If I'm understanding correctly, I think the simplest approach would be to do two replaces on the resourceName:

"serverName": a['resourceName'].replace('vSAN Cluster(','').replace(')',''),

This strips out the leading "vSAN Cluster(" and following ")".  It assumes you're using the python shim server and your cluster names don't have a closing parenthesis ")" in them.  A more precise approach would probably be to use a regular expression to only match the value between the beginning and ending parenthesis, but I'm not great at regular expressions and don't have a convenient way to test it.  As long as you don't have a closing parenthesis ")" in any cluster names this is simpler and should work.

View solution in original post

0 Kudos
2 Replies
dtaliafe
Hot Shot
Hot Shot
Jump to solution

If I'm understanding correctly, I think the simplest approach would be to do two replaces on the resourceName:

"serverName": a['resourceName'].replace('vSAN Cluster(','').replace(')',''),

This strips out the leading "vSAN Cluster(" and following ")".  It assumes you're using the python shim server and your cluster names don't have a closing parenthesis ")" in them.  A more precise approach would probably be to use a regular expression to only match the value between the beginning and ending parenthesis, but I'm not great at regular expressions and don't have a convenient way to test it.  As long as you don't have a closing parenthesis ")" in any cluster names this is simpler and should work.

0 Kudos
sxnxr
Commander
Commander
Jump to solution

This work great. the full section we use is

payload = {

      "result": {

           "TransformerName": "VMWare",

           "AlertMessage": a['info'],

           "EventInstance": a['subType'],

           "Criticality": a['criticality'],

           "EventName": a['AlertName'],

           "HostName": a['resourceName'].replace('.domain.com','').replace('vSAN Cluster(','').replace(')',''),

           "EventType": a['type'],

           "EventSubType": a['subType'],

           "type": "link",

           "url": a['url'],

0 Kudos