openzeppelin_monitor/models/core/
trigger.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
use crate::models::{core::ScriptLanguage, SecretValue};
use email_address::EmailAddress;
use serde::{Deserialize, Serialize};

/// Configuration for actions to take when monitored conditions are met.
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
#[serde(deny_unknown_fields)]
pub struct Trigger {
	/// Unique name identifying this trigger
	pub name: String,

	/// Type of trigger (Email, Slack, Webhook, Telegram, Discord, Script)
	pub trigger_type: TriggerType,

	/// Configuration specific to the trigger type
	pub config: TriggerTypeConfig,
}

/// Supported trigger action types
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
#[serde(rename_all = "lowercase")]
#[serde(deny_unknown_fields)]
pub enum TriggerType {
	/// Send notification to Slack
	Slack,
	/// Send notification to email
	Email,
	/// Make HTTP request to webhook
	Webhook,
	/// Send notification to Telegram
	Telegram,
	/// Send notification to Discord
	Discord,
	/// Execute local script
	Script,
}

/// Notification message fields
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
#[serde(deny_unknown_fields)]
pub struct NotificationMessage {
	/// Notification title or subject
	pub title: String,
	/// Message template
	pub body: String,
}

/// Type-specific configuration for triggers
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
#[serde(deny_unknown_fields)]
#[serde(untagged)]
pub enum TriggerTypeConfig {
	/// Slack notification configuration
	Slack {
		/// Slack webhook URL
		slack_url: SecretValue,
		/// Notification message
		message: NotificationMessage,
	},
	/// Email notification configuration
	Email {
		/// SMTP host
		host: String,
		/// SMTP port (default 465)
		port: Option<u16>,
		/// SMTP username
		username: SecretValue,
		/// SMTP password
		password: SecretValue,
		/// Notification message
		message: NotificationMessage,
		/// Email sender
		sender: EmailAddress,
		/// Email recipients
		recipients: Vec<EmailAddress>,
	},
	/// Webhook configuration
	Webhook {
		/// Webhook endpoint URL
		url: SecretValue,
		/// HTTP method to use
		method: Option<String>,
		/// Secret
		secret: Option<SecretValue>,
		/// Optional HTTP headers
		headers: Option<std::collections::HashMap<String, String>>,
		/// Notification message
		message: NotificationMessage,
	},
	/// Telegram notification configuration
	Telegram {
		/// Telegram bot token
		token: SecretValue,
		/// Telegram chat ID
		chat_id: String,
		/// Disable web preview
		disable_web_preview: Option<bool>,
		/// Notification message
		message: NotificationMessage,
	},
	/// Discord notification configuration
	Discord {
		/// Discord webhook URL
		discord_url: SecretValue,
		/// Notification message
		message: NotificationMessage,
	},
	/// Script execution configuration
	Script {
		/// Language of the script
		language: ScriptLanguage,
		/// Path to script file
		script_path: String,
		/// Command line arguments
		#[serde(default)]
		arguments: Option<Vec<String>>,
		/// Timeout in milliseconds
		timeout_ms: u32,
	},
}