tcplugins / tcWebHooks

WebHooks plugin for Teamcity. Supports many build states and payload formats.
https://netwolfuk.wordpress.com/category/teamcity/tcplugins/tcwebhooks/
154 stars 30 forks source link

Cloud Profiles "Events" #230

Open Super8film87 opened 9 months ago

Super8film87 commented 9 months ago

Hey,

I was asking myself what would be needed to send "events" if e.g.

By today handling all agents with a mix of cloud profiles is really complicated. Once somebody did a change it is hard to monitor so I proposed to have a look to use the webhooks maybe in the future. Do you have any thoughts about that?

netwolfuk commented 9 months ago

The first two might be possible. Not sure about the third.

These are the events that it's possible to listen for:

netwolfuk commented 9 months ago

Every event is quite a lot of work to implement for me. You might be able to get the same information from watching the log files on the server, and pushing that to Elastic.

Super8film87 commented 9 months ago

I found some information that I want to use:

## "cloudprofil" : [
## #foreach ($feature in $project.getAvailableFeatures())    
##         #if ($feature.getType() == 'CloudImage' && $feature.getParameters().get("image-name-prefix").startsWith("AGENT_"))
##             ##if ($feature.getParameters().get("image-name-prefix").startsWith("AGENT_"))
##             {
##                 #foreach ($param in $feature.getParameters().keySet())
##                     #if (!$param.startsWith("user-script"))
##                     "$param" : "$feature.getParameters().get($param)" #if( $foreach.hasNext ),#end
##                     #end
##                 #end
##             }#if( $foreach.hasNext ),#end
##             #end
##         #end
## #end
## ],
....

problem is that I dont understand how to identified latest item :(

netwolfuk commented 7 months ago

Hi @Super8film87 I don't have any cloud profiles enabled, so I am unsure what information you get.

How do you define "latest item"? Do you just mean the first matching item in the keyset? Or the last matching item in the keySet?

Having a quick look at this code above I have the following suggestions:

  1. Trying using getAvailableFeaturesOfType​('cloudImage'), then you can remove the first statement in the if where it checks with getType().
  2. The problem as I see it is that the last value in the foreach might not be user-script, so you can't assume that hasNext will behave as you want it. You might be more successful creating a new array, and putting the user-script items into it when you find them. Then iterate over that array when building the JSON.