@@ -25,9 +25,11 @@ use log::debug;
2525use log:: error;
2626use log:: info;
2727use log:: LevelFilter ;
28+ use metrics:: webhook_sender:: MetricsWebhookSender ;
2829use metrics:: MetricsContext ;
2930use plugins:: node_groups:: NodeGroupConfiguration ;
3031use plugins:: node_groups:: NodeGroupsPlugin ;
32+ use plugins:: webhook:: WebhookConfig ;
3133use plugins:: webhook:: WebhookPlugin ;
3234use plugins:: SchedulerPlugin ;
3335use plugins:: StatusUpdatePlugin ;
@@ -112,10 +114,6 @@ struct Args {
112114 #[ arg( short = 'l' , long, default_value = "info" ) ]
113115 log_level : String ,
114116
115- /// Webhook urls (comma-separated string)
116- #[ arg( long, default_value = "" ) ]
117- webhook_urls : Option < String > ,
118-
119117 /// Node group management interval
120118 #[ arg( long, default_value = "10" ) ]
121119 node_group_management_interval : u64 ,
@@ -199,6 +197,40 @@ async fn main() -> Result<()> {
199197 let mut scheduler_plugins: Vec < Box < dyn SchedulerPlugin > > = Vec :: new ( ) ;
200198 let mut status_update_plugins: Vec < Box < dyn StatusUpdatePlugin > > = vec ! [ ] ;
201199 let mut node_groups_plugin: Option < Arc < NodeGroupsPlugin > > = None ;
200+ let mut webhook_plugins: Vec < WebhookPlugin > = vec ! [ ] ;
201+
202+ let configs = std:: env:: var ( "WEBHOOK_CONFIGS" ) . unwrap_or_default ( ) ;
203+ match serde_json:: from_str :: < Vec < WebhookConfig > > ( & configs) {
204+ Ok ( configs) if !configs. is_empty ( ) => {
205+ for config in configs {
206+ let plugin = WebhookPlugin :: new ( config) ;
207+ let plugin_clone = plugin. clone ( ) ;
208+ webhook_plugins. push ( plugin_clone) ;
209+ status_update_plugins. push ( Box :: new ( plugin) ) ;
210+ }
211+ }
212+ Ok ( _) => {
213+ info ! ( "No webhook configurations provided" ) ;
214+ }
215+ Err ( e) => {
216+ error ! ( "Failed to parse webhook configs from environment: {}" , e) ;
217+ }
218+ }
219+
220+ let webhook_sender_store = store_context. clone ( ) ;
221+ let webhook_plugins_clone = webhook_plugins. clone ( ) ;
222+ if !webhook_plugins_clone. is_empty ( ) {
223+ tasks. spawn ( async move {
224+ let mut webhook_sender = MetricsWebhookSender :: new (
225+ webhook_sender_store. clone ( ) ,
226+ webhook_plugins_clone. clone ( ) ,
227+ ) ;
228+ if let Err ( e) = webhook_sender. run ( ) . await {
229+ error ! ( "Error running webhook sender: {}" , e) ;
230+ }
231+ Ok ( ( ) )
232+ } ) ;
233+ }
202234
203235 // Load node group configurations from environment variable
204236 if let Ok ( configs_json) = std:: env:: var ( "NODE_GROUP_CONFIGS" ) {
@@ -210,13 +242,14 @@ async fn main() -> Result<()> {
210242 store. clone ( ) ,
211243 group_store_context. clone ( ) ,
212244 Some ( node_groups_heartbeats. clone ( ) ) ,
245+ Some ( webhook_plugins. clone ( ) ) ,
213246 ) ;
214247 let status_group_plugin = group_plugin. clone ( ) ;
215248 let group_plugin_for_server = group_plugin. clone ( ) ;
216249 node_groups_plugin = Some ( Arc :: new ( group_plugin_for_server) ) ;
217250 scheduler_plugins. push ( Box :: new ( group_plugin) ) ;
218251 status_update_plugins. push ( Box :: new ( status_group_plugin) ) ;
219- info ! ( "Node group plugin initialized" , ) ;
252+ info ! ( "Node group plugin initialized" ) ;
220253 }
221254 Ok ( _) => {
222255 info ! (
@@ -277,17 +310,6 @@ async fn main() -> Result<()> {
277310 let status_update_store_context = store_context. clone ( ) ;
278311 let status_update_heartbeats = heartbeats. clone ( ) ;
279312 let status_update_contracts = contracts. clone ( ) ;
280- let webhook_urls: Vec < String > = args
281- . webhook_urls
282- . clone ( )
283- . unwrap_or_default ( )
284- . split ( ',' )
285- . map ( |s| s. to_string ( ) )
286- . collect ( ) ;
287-
288- for url in webhook_urls {
289- status_update_plugins. push ( Box :: new ( WebhookPlugin :: new ( url. to_string ( ) ) ) ) ;
290- }
291313
292314 tasks. spawn ( async move {
293315 let status_updater = NodeStatusUpdater :: new (
0 commit comments