diff --git a/Appwrite/Appwrite.csproj b/Appwrite/Appwrite.csproj index 339298d6..85b4ddb0 100644 --- a/Appwrite/Appwrite.csproj +++ b/Appwrite/Appwrite.csproj @@ -2,7 +2,7 @@ netstandard2.0;net462 Appwrite - 11.4.0 + 11.5.0 Appwrite Team Appwrite Team diff --git a/Appwrite/Client.cs b/Appwrite/Client.cs index 121f24f1..ac786196 100644 --- a/Appwrite/Client.cs +++ b/Appwrite/Client.cs @@ -93,11 +93,11 @@ public Client( _headers = new Dictionary() { { "content-type", "application/json" }, - { "user-agent", $"AppwriteDotNetSDK/11.4.0 ({System.Environment.OSVersion.Platform}; {System.Environment.OSVersion.VersionString})"}, + { "user-agent", $"AppwriteDotNetSDK/11.5.0 ({System.Environment.OSVersion.Platform}; {System.Environment.OSVersion.VersionString})"}, { "x-sdk-name", ".NET" }, { "x-sdk-platform", "server" }, { "x-sdk-language", "dotnet" }, - { "x-sdk-version", "11.4.0"}, + { "x-sdk-version", "11.5.0"}, { "X-Appwrite-Response-Format", "2.7.2" } }; diff --git a/Appwrite/Enums/AlertComparator.cs b/Appwrite/Enums/AlertComparator.cs new file mode 100644 index 00000000..9ccf608a --- /dev/null +++ b/Appwrite/Enums/AlertComparator.cs @@ -0,0 +1,19 @@ +using System; + +namespace Appwrite.Enums +{ + public class AlertComparator : IEnum + { + public string Value { get; private set; } + + public AlertComparator(string value) + { + Value = value; + } + + public static AlertComparator GreaterThan => new AlertComparator("greaterThan"); + public static AlertComparator GreaterThanEqual => new AlertComparator("greaterThanEqual"); + public static AlertComparator LessThan => new AlertComparator("lessThan"); + public static AlertComparator LessThanEqual => new AlertComparator("lessThanEqual"); + } +} diff --git a/Appwrite/Enums/AlertMetric.cs b/Appwrite/Enums/AlertMetric.cs new file mode 100644 index 00000000..88bcbcce --- /dev/null +++ b/Appwrite/Enums/AlertMetric.cs @@ -0,0 +1,45 @@ +using System; + +namespace Appwrite.Enums +{ + public class AlertMetric : IEnum + { + public string Value { get; private set; } + + public AlertMetric(string value) + { + Value = value; + } + + public static AlertMetric NetworkRequests => new AlertMetric("network.requests"); + public static AlertMetric NetworkInbound => new AlertMetric("network.inbound"); + public static AlertMetric NetworkOutbound => new AlertMetric("network.outbound"); + public static AlertMetric Executions => new AlertMetric("executions"); + public static AlertMetric ExecutionsMbSeconds => new AlertMetric("executions.mbSeconds"); + public static AlertMetric RealtimeConnections => new AlertMetric("realtime.connections"); + public static AlertMetric WebhooksEventsSent => new AlertMetric("webhooks.events.sent"); + public static AlertMetric WebhooksEventsFailed => new AlertMetric("webhooks.events.failed"); + public static AlertMetric UsersMau => new AlertMetric("users.mau"); + public static AlertMetric AuthMethodPhone => new AlertMetric("auth.method.phone"); + public static AlertMetric Users => new AlertMetric("users"); + public static AlertMetric DatabasesOperationsReads => new AlertMetric("databases.operations.reads"); + public static AlertMetric DatabasesOperationsWrites => new AlertMetric("databases.operations.writes"); + public static AlertMetric DatabasesStorage => new AlertMetric("databases.storage"); + public static AlertMetric Storage => new AlertMetric("storage"); + public static AlertMetric FilesStorage => new AlertMetric("files.storage"); + public static AlertMetric MessagesSent => new AlertMetric("messages.sent"); + public static AlertMetric MessagesSmsSent => new AlertMetric("messages.sms.sent"); + public static AlertMetric MessagesFailed => new AlertMetric("messages.failed"); + public static AlertMetric AvatarsScreenshotsGenerated => new AlertMetric("avatars.screenshotsGenerated"); + public static AlertMetric DedicatedDatabasesCpu => new AlertMetric("dedicatedDatabases.cpu"); + public static AlertMetric DedicatedDatabasesMemory => new AlertMetric("dedicatedDatabases.memory"); + public static AlertMetric DedicatedDatabasesStorage => new AlertMetric("dedicatedDatabases.storage"); + public static AlertMetric DedicatedDatabasesConnections => new AlertMetric("dedicatedDatabases.connections"); + public static AlertMetric DedicatedDatabasesQps => new AlertMetric("dedicatedDatabases.qps"); + public static AlertMetric DedicatedDatabasesIopsRead => new AlertMetric("dedicatedDatabases.iopsRead"); + public static AlertMetric DedicatedDatabasesIopsWrite => new AlertMetric("dedicatedDatabases.iopsWrite"); + public static AlertMetric AnalyticsEvents => new AlertMetric("analytics.events"); + public static AlertMetric AnalyticsPageviews => new AlertMetric("analytics.pageviews"); + public static AlertMetric BillingBudgetUsed => new AlertMetric("billing.budgetUsed"); + } +} diff --git a/Appwrite/Enums/AlertStatus.cs b/Appwrite/Enums/AlertStatus.cs new file mode 100644 index 00000000..4a2f405d --- /dev/null +++ b/Appwrite/Enums/AlertStatus.cs @@ -0,0 +1,17 @@ +using System; + +namespace Appwrite.Enums +{ + public class AlertStatus : IEnum + { + public string Value { get; private set; } + + public AlertStatus(string value) + { + Value = value; + } + + public static AlertStatus Firing => new AlertStatus("firing"); + public static AlertStatus Resolved => new AlertStatus("resolved"); + } +} diff --git a/Appwrite/Enums/MonitorMethod.cs b/Appwrite/Enums/MonitorMethod.cs new file mode 100644 index 00000000..83c1c888 --- /dev/null +++ b/Appwrite/Enums/MonitorMethod.cs @@ -0,0 +1,22 @@ +using System; + +namespace Appwrite.Enums +{ + public class MonitorMethod : IEnum + { + public string Value { get; private set; } + + public MonitorMethod(string value) + { + Value = value; + } + + public static MonitorMethod GET => new MonitorMethod("GET"); + public static MonitorMethod HEAD => new MonitorMethod("HEAD"); + public static MonitorMethod POST => new MonitorMethod("POST"); + public static MonitorMethod PUT => new MonitorMethod("PUT"); + public static MonitorMethod PATCH => new MonitorMethod("PATCH"); + public static MonitorMethod DELETE => new MonitorMethod("DELETE"); + public static MonitorMethod OPTIONS => new MonitorMethod("OPTIONS"); + } +} diff --git a/Appwrite/Enums/MonitorRecord.cs b/Appwrite/Enums/MonitorRecord.cs new file mode 100644 index 00000000..9abca656 --- /dev/null +++ b/Appwrite/Enums/MonitorRecord.cs @@ -0,0 +1,21 @@ +using System; + +namespace Appwrite.Enums +{ + public class MonitorRecord : IEnum + { + public string Value { get; private set; } + + public MonitorRecord(string value) + { + Value = value; + } + + public static MonitorRecord A => new MonitorRecord("A"); + public static MonitorRecord AAAA => new MonitorRecord("AAAA"); + public static MonitorRecord CNAME => new MonitorRecord("CNAME"); + public static MonitorRecord MX => new MonitorRecord("MX"); + public static MonitorRecord TXT => new MonitorRecord("TXT"); + public static MonitorRecord NS => new MonitorRecord("NS"); + } +} diff --git a/Appwrite/Enums/MonitorResourceType.cs b/Appwrite/Enums/MonitorResourceType.cs new file mode 100644 index 00000000..58e34a3b --- /dev/null +++ b/Appwrite/Enums/MonitorResourceType.cs @@ -0,0 +1,22 @@ +using System; + +namespace Appwrite.Enums +{ + public class MonitorResourceType : IEnum + { + public string Value { get; private set; } + + public MonitorResourceType(string value) + { + Value = value; + } + + public static MonitorResourceType Project => new MonitorResourceType("project"); + public static MonitorResourceType Database => new MonitorResourceType("database"); + public static MonitorResourceType Bucket => new MonitorResourceType("bucket"); + public static MonitorResourceType Function => new MonitorResourceType("function"); + public static MonitorResourceType Site => new MonitorResourceType("site"); + public static MonitorResourceType DedicatedDatabase => new MonitorResourceType("dedicatedDatabase"); + public static MonitorResourceType Organization => new MonitorResourceType("organization"); + } +} diff --git a/Appwrite/Enums/MonitorResult.cs b/Appwrite/Enums/MonitorResult.cs new file mode 100644 index 00000000..d9d6672f --- /dev/null +++ b/Appwrite/Enums/MonitorResult.cs @@ -0,0 +1,28 @@ +using System; + +namespace Appwrite.Enums +{ + public class MonitorResult : IEnum + { + public string Value { get; private set; } + + public MonitorResult(string value) + { + Value = value; + } + + public static MonitorResult Ok => new MonitorResult("ok"); + public static MonitorResult DnsFailed => new MonitorResult("dns_failed"); + public static MonitorResult ConnectRefused => new MonitorResult("connect_refused"); + public static MonitorResult ConnectTimeout => new MonitorResult("connect_timeout"); + public static MonitorResult ConnectFailed => new MonitorResult("connect_failed"); + public static MonitorResult TlsFailed => new MonitorResult("tls_failed"); + public static MonitorResult TlsExpiring => new MonitorResult("tls_expiring"); + public static MonitorResult StatusMismatch => new MonitorResult("status_mismatch"); + public static MonitorResult AnswerMismatch => new MonitorResult("answer_mismatch"); + public static MonitorResult SmtpRejected => new MonitorResult("smtp_rejected"); + public static MonitorResult TargetDenied => new MonitorResult("target_denied"); + public static MonitorResult Timeout => new MonitorResult("timeout"); + public static MonitorResult RuleMatched => new MonitorResult("rule_matched"); + } +} diff --git a/Appwrite/Enums/MonitorSeverity.cs b/Appwrite/Enums/MonitorSeverity.cs new file mode 100644 index 00000000..822a4324 --- /dev/null +++ b/Appwrite/Enums/MonitorSeverity.cs @@ -0,0 +1,19 @@ +using System; + +namespace Appwrite.Enums +{ + public class MonitorSeverity : IEnum + { + public string Value { get; private set; } + + public MonitorSeverity(string value) + { + Value = value; + } + + public static MonitorSeverity Info => new MonitorSeverity("info"); + public static MonitorSeverity Warning => new MonitorSeverity("warning"); + public static MonitorSeverity Error => new MonitorSeverity("error"); + public static MonitorSeverity Critical => new MonitorSeverity("critical"); + } +} diff --git a/Appwrite/Enums/MonitorStatus.cs b/Appwrite/Enums/MonitorStatus.cs new file mode 100644 index 00000000..8067b64c --- /dev/null +++ b/Appwrite/Enums/MonitorStatus.cs @@ -0,0 +1,17 @@ +using System; + +namespace Appwrite.Enums +{ + public class MonitorStatus : IEnum + { + public string Value { get; private set; } + + public MonitorStatus(string value) + { + Value = value; + } + + public static MonitorStatus Ok => new MonitorStatus("ok"); + public static MonitorStatus Firing => new MonitorStatus("firing"); + } +} diff --git a/Appwrite/Enums/MonitorTlsMode.cs b/Appwrite/Enums/MonitorTlsMode.cs new file mode 100644 index 00000000..4c11e2cf --- /dev/null +++ b/Appwrite/Enums/MonitorTlsMode.cs @@ -0,0 +1,19 @@ +using System; + +namespace Appwrite.Enums +{ + public class MonitorTlsMode : IEnum + { + public string Value { get; private set; } + + public MonitorTlsMode(string value) + { + Value = value; + } + + public static MonitorTlsMode None => new MonitorTlsMode("none"); + public static MonitorTlsMode Starttls => new MonitorTlsMode("starttls"); + public static MonitorTlsMode Implicit => new MonitorTlsMode("implicit"); + public static MonitorTlsMode Auto => new MonitorTlsMode("auto"); + } +} diff --git a/Appwrite/Enums/MonitorType.cs b/Appwrite/Enums/MonitorType.cs new file mode 100644 index 00000000..39444b74 --- /dev/null +++ b/Appwrite/Enums/MonitorType.cs @@ -0,0 +1,21 @@ +using System; + +namespace Appwrite.Enums +{ + public class MonitorType : IEnum + { + public string Value { get; private set; } + + public MonitorType(string value) + { + Value = value; + } + + public static MonitorType Usage => new MonitorType("usage"); + public static MonitorType Http => new MonitorType("http"); + public static MonitorType Dns => new MonitorType("dns"); + public static MonitorType Tcp => new MonitorType("tcp"); + public static MonitorType Smtp => new MonitorType("smtp"); + public static MonitorType Budget => new MonitorType("budget"); + } +} diff --git a/Appwrite/Models/Alert.cs b/Appwrite/Models/Alert.cs new file mode 100644 index 00000000..6e4a1172 --- /dev/null +++ b/Appwrite/Models/Alert.cs @@ -0,0 +1,236 @@ + +using System; +using System.Linq; +using System.Collections.Generic; +using System.Text.Json; +using System.Text.Json.Serialization; +using Appwrite.Enums; +using Appwrite.Extensions; + +namespace Appwrite.Models +{ + public class Alert + { + [JsonPropertyName("$id")] + public string Id { get; private set; } + + [JsonPropertyName("$createdAt")] + public string CreatedAt { get; private set; } + + [JsonPropertyName("$updatedAt")] + public string UpdatedAt { get; private set; } + + [JsonPropertyName("monitorId")] + public string MonitorId { get; private set; } + + [JsonPropertyName("projectId")] + public string ProjectId { get; private set; } + + [JsonPropertyName("name")] + public string Name { get; private set; } + + [JsonPropertyName("status")] + public Appwrite.Enums.AlertStatus Status { get; private set; } + + [JsonPropertyName("resolvedAt")] + public string? ResolvedAt { get; private set; } + + [JsonPropertyName("acknowledgedAt")] + public string? AcknowledgedAt { get; private set; } + + [JsonPropertyName("acknowledgedBy")] + public string AcknowledgedBy { get; private set; } + + [JsonPropertyName("acknowledgedByName")] + public string AcknowledgedByName { get; private set; } + + [JsonPropertyName("escalationId")] + public string EscalationId { get; private set; } + + [JsonPropertyName("escalationStep")] + public long EscalationStep { get; private set; } + + [JsonPropertyName("escalationRound")] + public long EscalationRound { get; private set; } + + [JsonPropertyName("escalatesAt")] + public string? EscalatesAt { get; private set; } + + [JsonPropertyName("rules")] + public List Rules { get; private set; } + + [JsonPropertyName("severity")] + public Appwrite.Enums.MonitorSeverity Severity { get; private set; } + + [JsonPropertyName("metric")] + public Appwrite.Enums.AlertMetric? Metric { get; private set; } + + [JsonPropertyName("comparator")] + public Appwrite.Enums.AlertComparator? Comparator { get; private set; } + + [JsonPropertyName("threshold")] + public double Threshold { get; private set; } + + [JsonPropertyName("value")] + public double Value { get; private set; } + + [JsonPropertyName("peak")] + public double Peak { get; private set; } + + [JsonPropertyName("type")] + public Appwrite.Enums.MonitorType Type { get; private set; } + + [JsonPropertyName("resourceType")] + public Appwrite.Enums.MonitorResourceType ResourceType { get; private set; } + + [JsonPropertyName("resourceId")] + public string ResourceId { get; private set; } + + [JsonPropertyName("notifications")] + public long Notifications { get; private set; } + + [JsonPropertyName("latency")] + public long? Latency { get; private set; } + + [JsonPropertyName("result")] + public Appwrite.Enums.MonitorResult? Result { get; private set; } + + public Alert( + string id, + string createdAt, + string updatedAt, + string monitorId, + string projectId, + string name, + Appwrite.Enums.AlertStatus status, + string? resolvedAt, + string? acknowledgedAt, + string acknowledgedBy, + string acknowledgedByName, + string escalationId, + long escalationStep, + long escalationRound, + string? escalatesAt, + List rules, + Appwrite.Enums.MonitorSeverity severity, + Appwrite.Enums.AlertMetric? metric, + Appwrite.Enums.AlertComparator? comparator, + double threshold, + double @value, + double peak, + Appwrite.Enums.MonitorType type, + Appwrite.Enums.MonitorResourceType resourceType, + string resourceId, + long notifications, + long? latency, + Appwrite.Enums.MonitorResult? result + ) + { + Id = id; + CreatedAt = createdAt; + UpdatedAt = updatedAt; + MonitorId = monitorId; + ProjectId = projectId; + Name = name; + Status = status; + ResolvedAt = resolvedAt; + AcknowledgedAt = acknowledgedAt; + AcknowledgedBy = acknowledgedBy; + AcknowledgedByName = acknowledgedByName; + EscalationId = escalationId; + EscalationStep = escalationStep; + EscalationRound = escalationRound; + EscalatesAt = escalatesAt; + Rules = rules; + Severity = severity; + Metric = metric; + Comparator = comparator; + Threshold = threshold; + Value = @value; + Peak = peak; + Type = type; + ResourceType = resourceType; + ResourceId = resourceId; + Notifications = notifications; + Latency = latency; + Result = result; + } + + public static Alert From(Dictionary map) => new Alert( + id: (map.ContainsKey("$id") ? map["$id"] : "").ToString(), + createdAt: (map.ContainsKey("$createdAt") ? map["$createdAt"] : "").ToString(), + updatedAt: (map.ContainsKey("$updatedAt") ? map["$updatedAt"] : "").ToString(), + monitorId: (map.ContainsKey("monitorId") ? map["monitorId"] : "").ToString(), + projectId: (map.ContainsKey("projectId") ? map["projectId"] : "").ToString(), + name: (map.ContainsKey("name") ? map["name"] : "").ToString(), + status: new Appwrite.Enums.AlertStatus((map.ContainsKey("status") ? map["status"] : "firing").ToString()!), + resolvedAt: map.TryGetValue("resolvedAt", out var resolvedAt) ? resolvedAt?.ToString() : null, + acknowledgedAt: map.TryGetValue("acknowledgedAt", out var acknowledgedAt) ? acknowledgedAt?.ToString() : null, + acknowledgedBy: (map.ContainsKey("acknowledgedBy") ? map["acknowledgedBy"] : "").ToString(), + acknowledgedByName: (map.ContainsKey("acknowledgedByName") ? map["acknowledgedByName"] : "").ToString(), + escalationId: (map.ContainsKey("escalationId") ? map["escalationId"] : "").ToString(), + escalationStep: Convert.ToInt64((map.ContainsKey("escalationStep") ? map["escalationStep"] : 0)), + escalationRound: Convert.ToInt64((map.ContainsKey("escalationRound") ? map["escalationRound"] : 0)), + escalatesAt: map.TryGetValue("escalatesAt", out var escalatesAt) ? escalatesAt?.ToString() : null, + rules: (map.ContainsKey("rules") ? map["rules"] : new List()).ConvertToList(), + severity: new Appwrite.Enums.MonitorSeverity((map.ContainsKey("severity") ? map["severity"] : "warning").ToString()!), + metric: map.TryGetValue("metric", out var enumRaw18) + ? enumRaw18 == null + ? null + : new Appwrite.Enums.AlertMetric(enumRaw18.ToString()!) + : null, + comparator: map.TryGetValue("comparator", out var enumRaw19) + ? enumRaw19 == null + ? null + : new Appwrite.Enums.AlertComparator(enumRaw19.ToString()!) + : null, + threshold: Convert.ToDouble((map.ContainsKey("threshold") ? map["threshold"] : 0)), + @value: Convert.ToDouble((map.ContainsKey("value") ? map["value"] : 0)), + peak: Convert.ToDouble((map.ContainsKey("peak") ? map["peak"] : 0)), + type: new Appwrite.Enums.MonitorType((map.ContainsKey("type") ? map["type"] : "usage").ToString()!), + resourceType: new Appwrite.Enums.MonitorResourceType((map.ContainsKey("resourceType") ? map["resourceType"] : "project").ToString()!), + resourceId: (map.ContainsKey("resourceId") ? map["resourceId"] : "").ToString(), + notifications: Convert.ToInt64((map.ContainsKey("notifications") ? map["notifications"] : 0)), + latency: map.TryGetValue("latency", out var numberRaw27) && numberRaw27 != null + ? Convert.ToInt64(numberRaw27) + : null, + result: map.TryGetValue("result", out var enumRaw28) + ? enumRaw28 == null + ? null + : new Appwrite.Enums.MonitorResult(enumRaw28.ToString()!) + : null + ); + + public Dictionary ToMap() => new Dictionary() + { + { "$id", Id }, + { "$createdAt", CreatedAt }, + { "$updatedAt", UpdatedAt }, + { "monitorId", MonitorId }, + { "projectId", ProjectId }, + { "name", Name }, + { "status", Status.Value }, + { "resolvedAt", ResolvedAt }, + { "acknowledgedAt", AcknowledgedAt }, + { "acknowledgedBy", AcknowledgedBy }, + { "acknowledgedByName", AcknowledgedByName }, + { "escalationId", EscalationId }, + { "escalationStep", EscalationStep }, + { "escalationRound", EscalationRound }, + { "escalatesAt", EscalatesAt }, + { "rules", Rules }, + { "severity", Severity.Value }, + { "metric", Metric?.Value }, + { "comparator", Comparator?.Value }, + { "threshold", Threshold }, + { "value", Value }, + { "peak", Peak }, + { "type", Type.Value }, + { "resourceType", ResourceType.Value }, + { "resourceId", ResourceId }, + { "notifications", Notifications }, + { "latency", Latency }, + { "result", Result?.Value } + }; + } +} diff --git a/Appwrite/Models/AlertList.cs b/Appwrite/Models/AlertList.cs new file mode 100644 index 00000000..1528d38d --- /dev/null +++ b/Appwrite/Models/AlertList.cs @@ -0,0 +1,40 @@ + +using System; +using System.Linq; +using System.Collections.Generic; +using System.Text.Json; +using System.Text.Json.Serialization; +using Appwrite.Enums; +using Appwrite.Extensions; + +namespace Appwrite.Models +{ + public class AlertList + { + [JsonPropertyName("total")] + public long Total { get; private set; } + + [JsonPropertyName("alerts")] + public List Alerts { get; private set; } + + public AlertList( + long total, + List alerts + ) + { + Total = total; + Alerts = alerts; + } + + public static AlertList From(Dictionary map) => new AlertList( + total: Convert.ToInt64((map.ContainsKey("total") ? map["total"] : 0)), + alerts: (map.ContainsKey("alerts") ? map["alerts"] : new List()).ConvertToList>().Select(it => Appwrite.Models.Alert.From(map: it)).ToList() + ); + + public Dictionary ToMap() => new Dictionary() + { + { "total", Total }, + { "alerts", Alerts?.Select(it => it.ToMap()).ToList() } + }; + } +} diff --git a/Appwrite/Models/Escalation.cs b/Appwrite/Models/Escalation.cs new file mode 100644 index 00000000..de5c3168 --- /dev/null +++ b/Appwrite/Models/Escalation.cs @@ -0,0 +1,68 @@ + +using System; +using System.Linq; +using System.Collections.Generic; +using System.Text.Json; +using System.Text.Json.Serialization; +using Appwrite.Enums; +using Appwrite.Extensions; + +namespace Appwrite.Models +{ + public class Escalation + { + [JsonPropertyName("$id")] + public string Id { get; private set; } + + [JsonPropertyName("$createdAt")] + public string CreatedAt { get; private set; } + + [JsonPropertyName("$updatedAt")] + public string UpdatedAt { get; private set; } + + [JsonPropertyName("name")] + public string Name { get; private set; } + + [JsonPropertyName("steps")] + public List Steps { get; private set; } + + [JsonPropertyName("repeat")] + public long Repeat { get; private set; } + + public Escalation( + string id, + string createdAt, + string updatedAt, + string name, + List steps, + long repeat + ) + { + Id = id; + CreatedAt = createdAt; + UpdatedAt = updatedAt; + Name = name; + Steps = steps; + Repeat = repeat; + } + + public static Escalation From(Dictionary map) => new Escalation( + id: (map.ContainsKey("$id") ? map["$id"] : "").ToString(), + createdAt: (map.ContainsKey("$createdAt") ? map["$createdAt"] : "").ToString(), + updatedAt: (map.ContainsKey("$updatedAt") ? map["$updatedAt"] : "").ToString(), + name: (map.ContainsKey("name") ? map["name"] : "").ToString(), + steps: (map.ContainsKey("steps") ? map["steps"] : new List()).ConvertToList>().Select(it => Appwrite.Models.EscalationStep.From(map: it)).ToList(), + repeat: Convert.ToInt64((map.ContainsKey("repeat") ? map["repeat"] : 0)) + ); + + public Dictionary ToMap() => new Dictionary() + { + { "$id", Id }, + { "$createdAt", CreatedAt }, + { "$updatedAt", UpdatedAt }, + { "name", Name }, + { "steps", Steps?.Select(it => it.ToMap()).ToList() }, + { "repeat", Repeat } + }; + } +} diff --git a/Appwrite/Models/EscalationList.cs b/Appwrite/Models/EscalationList.cs new file mode 100644 index 00000000..ee997277 --- /dev/null +++ b/Appwrite/Models/EscalationList.cs @@ -0,0 +1,40 @@ + +using System; +using System.Linq; +using System.Collections.Generic; +using System.Text.Json; +using System.Text.Json.Serialization; +using Appwrite.Enums; +using Appwrite.Extensions; + +namespace Appwrite.Models +{ + public class EscalationList + { + [JsonPropertyName("total")] + public long Total { get; private set; } + + [JsonPropertyName("escalations")] + public List Escalations { get; private set; } + + public EscalationList( + long total, + List escalations + ) + { + Total = total; + Escalations = escalations; + } + + public static EscalationList From(Dictionary map) => new EscalationList( + total: Convert.ToInt64((map.ContainsKey("total") ? map["total"] : 0)), + escalations: (map.ContainsKey("escalations") ? map["escalations"] : new List()).ConvertToList>().Select(it => Appwrite.Models.Escalation.From(map: it)).ToList() + ); + + public Dictionary ToMap() => new Dictionary() + { + { "total", Total }, + { "escalations", Escalations?.Select(it => it.ToMap()).ToList() } + }; + } +} diff --git a/Appwrite/Models/EscalationStep.cs b/Appwrite/Models/EscalationStep.cs new file mode 100644 index 00000000..d5d4a1e9 --- /dev/null +++ b/Appwrite/Models/EscalationStep.cs @@ -0,0 +1,47 @@ + +using System; +using System.Linq; +using System.Collections.Generic; +using System.Text.Json; +using System.Text.Json.Serialization; +using Appwrite.Enums; +using Appwrite.Extensions; + +namespace Appwrite.Models +{ + public class EscalationStep + { + [JsonPropertyName("delay")] + public long Delay { get; private set; } + + [JsonPropertyName("roles")] + public List Roles { get; private set; } + + [JsonPropertyName("userIds")] + public List UserIds { get; private set; } + + public EscalationStep( + long delay, + List roles, + List userIds + ) + { + Delay = delay; + Roles = roles; + UserIds = userIds; + } + + public static EscalationStep From(Dictionary map) => new EscalationStep( + delay: Convert.ToInt64((map.ContainsKey("delay") ? map["delay"] : 0)), + roles: (map.ContainsKey("roles") ? map["roles"] : new List()).ConvertToList(), + userIds: (map.ContainsKey("userIds") ? map["userIds"] : new List()).ConvertToList() + ); + + public Dictionary ToMap() => new Dictionary() + { + { "delay", Delay }, + { "roles", Roles }, + { "userIds", UserIds } + }; + } +} diff --git a/Appwrite/Models/Monitor.cs b/Appwrite/Models/Monitor.cs new file mode 100644 index 00000000..cde92071 --- /dev/null +++ b/Appwrite/Models/Monitor.cs @@ -0,0 +1,300 @@ + +using System; +using System.Linq; +using System.Collections.Generic; +using System.Text.Json; +using System.Text.Json.Serialization; +using Appwrite.Enums; +using Appwrite.Extensions; + +namespace Appwrite.Models +{ + public class Monitor + { + [JsonPropertyName("$id")] + public string Id { get; private set; } + + [JsonPropertyName("$createdAt")] + public string CreatedAt { get; private set; } + + [JsonPropertyName("$updatedAt")] + public string UpdatedAt { get; private set; } + + [JsonPropertyName("name")] + public string Name { get; private set; } + + [JsonPropertyName("projectId")] + public string ProjectId { get; private set; } + + [JsonPropertyName("rules")] + public List Rules { get; private set; } + + [JsonPropertyName("type")] + public Appwrite.Enums.MonitorType Type { get; private set; } + + [JsonPropertyName("resourceType")] + public Appwrite.Enums.MonitorResourceType ResourceType { get; private set; } + + [JsonPropertyName("resourceId")] + public string ResourceId { get; private set; } + + [JsonPropertyName("window")] + public long Window { get; private set; } + + [JsonPropertyName("cooldown")] + public long Cooldown { get; private set; } + + [JsonPropertyName("enabled")] + public bool Enabled { get; private set; } + + [JsonPropertyName("notify")] + public List Notify { get; private set; } + + [JsonPropertyName("escalationId")] + public string EscalationId { get; private set; } + + [JsonPropertyName("severity")] + public Appwrite.Enums.MonitorSeverity Severity { get; private set; } + + [JsonPropertyName("status")] + public Appwrite.Enums.MonitorStatus Status { get; private set; } + + [JsonPropertyName("value")] + public double? Value { get; private set; } + + [JsonPropertyName("evaluatedAt")] + public string? EvaluatedAt { get; private set; } + + [JsonPropertyName("alertId")] + public string AlertId { get; private set; } + + [JsonPropertyName("triggeredAt")] + public string? TriggeredAt { get; private set; } + + [JsonPropertyName("interval")] + public long Interval { get; private set; } + + [JsonPropertyName("timeout")] + public long Timeout { get; private set; } + + [JsonPropertyName("url")] + public string Url { get; private set; } + + [JsonPropertyName("method")] + public Appwrite.Enums.MonitorMethod? Method { get; private set; } + + [JsonPropertyName("headers")] + public object? Headers { get; private set; } + + [JsonPropertyName("body")] + public string Body { get; private set; } + + [JsonPropertyName("domain")] + public string Domain { get; private set; } + + [JsonPropertyName("record")] + public Appwrite.Enums.MonitorRecord? Record { get; private set; } + + [JsonPropertyName("resolver")] + public string Resolver { get; private set; } + + [JsonPropertyName("host")] + public string Host { get; private set; } + + [JsonPropertyName("port")] + public long Port { get; private set; } + + [JsonPropertyName("tlsMode")] + public Appwrite.Enums.MonitorTlsMode? TlsMode { get; private set; } + + [JsonPropertyName("result")] + public Appwrite.Enums.MonitorResult? Result { get; private set; } + + [JsonPropertyName("latency")] + public long? Latency { get; private set; } + + [JsonPropertyName("code")] + public long? Code { get; private set; } + + [JsonPropertyName("certificateExpiresAt")] + public string? CertificateExpiresAt { get; private set; } + + public Monitor( + string id, + string createdAt, + string updatedAt, + string name, + string projectId, + List rules, + Appwrite.Enums.MonitorType type, + Appwrite.Enums.MonitorResourceType resourceType, + string resourceId, + long window, + long cooldown, + bool enabled, + List notify, + string escalationId, + Appwrite.Enums.MonitorSeverity severity, + Appwrite.Enums.MonitorStatus status, + double? @value, + string? evaluatedAt, + string alertId, + string? triggeredAt, + long interval, + long timeout, + string url, + Appwrite.Enums.MonitorMethod? method, + object? headers, + string body, + string domain, + Appwrite.Enums.MonitorRecord? record, + string resolver, + string host, + long port, + Appwrite.Enums.MonitorTlsMode? tlsMode, + Appwrite.Enums.MonitorResult? result, + long? latency, + long? code, + string? certificateExpiresAt + ) + { + Id = id; + CreatedAt = createdAt; + UpdatedAt = updatedAt; + Name = name; + ProjectId = projectId; + Rules = rules; + Type = type; + ResourceType = resourceType; + ResourceId = resourceId; + Window = window; + Cooldown = cooldown; + Enabled = enabled; + Notify = notify; + EscalationId = escalationId; + Severity = severity; + Status = status; + Value = @value; + EvaluatedAt = evaluatedAt; + AlertId = alertId; + TriggeredAt = triggeredAt; + Interval = interval; + Timeout = timeout; + Url = url; + Method = method; + Headers = headers; + Body = body; + Domain = domain; + Record = record; + Resolver = resolver; + Host = host; + Port = port; + TlsMode = tlsMode; + Result = result; + Latency = latency; + Code = code; + CertificateExpiresAt = certificateExpiresAt; + } + + public static Monitor From(Dictionary map) => new Monitor( + id: (map.ContainsKey("$id") ? map["$id"] : "").ToString(), + createdAt: (map.ContainsKey("$createdAt") ? map["$createdAt"] : "").ToString(), + updatedAt: (map.ContainsKey("$updatedAt") ? map["$updatedAt"] : "").ToString(), + name: (map.ContainsKey("name") ? map["name"] : "").ToString(), + projectId: (map.ContainsKey("projectId") ? map["projectId"] : "").ToString(), + rules: (map.ContainsKey("rules") ? map["rules"] : new List()).ConvertToList(), + type: new Appwrite.Enums.MonitorType((map.ContainsKey("type") ? map["type"] : "usage").ToString()!), + resourceType: new Appwrite.Enums.MonitorResourceType((map.ContainsKey("resourceType") ? map["resourceType"] : "project").ToString()!), + resourceId: (map.ContainsKey("resourceId") ? map["resourceId"] : "").ToString(), + window: Convert.ToInt64((map.ContainsKey("window") ? map["window"] : 3600)), + cooldown: Convert.ToInt64((map.ContainsKey("cooldown") ? map["cooldown"] : 3600)), + enabled: (bool)(map.ContainsKey("enabled") ? map["enabled"] : true), + notify: (map.ContainsKey("notify") ? map["notify"] : new List { "owner" }).ConvertToList(), + escalationId: (map.ContainsKey("escalationId") ? map["escalationId"] : "").ToString(), + severity: new Appwrite.Enums.MonitorSeverity((map.ContainsKey("severity") ? map["severity"] : "warning").ToString()!), + status: new Appwrite.Enums.MonitorStatus((map.ContainsKey("status") ? map["status"] : "ok").ToString()!), + @value: map.TryGetValue("value", out var numberRaw17) && numberRaw17 != null + ? Convert.ToDouble(numberRaw17) + : null, + evaluatedAt: map.TryGetValue("evaluatedAt", out var evaluatedAt) ? evaluatedAt?.ToString() : null, + alertId: (map.ContainsKey("alertId") ? map["alertId"] : "").ToString(), + triggeredAt: map.TryGetValue("triggeredAt", out var triggeredAt) ? triggeredAt?.ToString() : null, + interval: Convert.ToInt64((map.ContainsKey("interval") ? map["interval"] : 0)), + timeout: Convert.ToInt64((map.ContainsKey("timeout") ? map["timeout"] : 0)), + url: (map.ContainsKey("url") ? map["url"] : "").ToString(), + method: map.TryGetValue("method", out var enumRaw24) + ? enumRaw24 == null + ? null + : new Appwrite.Enums.MonitorMethod(enumRaw24.ToString()!) + : null, + headers: map.TryGetValue("headers", out var objectRaw25) ? objectRaw25 : null, + body: (map.ContainsKey("body") ? map["body"] : "").ToString(), + domain: (map.ContainsKey("domain") ? map["domain"] : "").ToString(), + record: map.TryGetValue("record", out var enumRaw28) + ? enumRaw28 == null + ? null + : new Appwrite.Enums.MonitorRecord(enumRaw28.ToString()!) + : null, + resolver: (map.ContainsKey("resolver") ? map["resolver"] : "").ToString(), + host: (map.ContainsKey("host") ? map["host"] : "").ToString(), + port: Convert.ToInt64((map.ContainsKey("port") ? map["port"] : 0)), + tlsMode: map.TryGetValue("tlsMode", out var enumRaw32) + ? enumRaw32 == null + ? null + : new Appwrite.Enums.MonitorTlsMode(enumRaw32.ToString()!) + : null, + result: map.TryGetValue("result", out var enumRaw33) + ? enumRaw33 == null + ? null + : new Appwrite.Enums.MonitorResult(enumRaw33.ToString()!) + : null, + latency: map.TryGetValue("latency", out var numberRaw34) && numberRaw34 != null + ? Convert.ToInt64(numberRaw34) + : null, + code: map.TryGetValue("code", out var numberRaw35) && numberRaw35 != null + ? Convert.ToInt64(numberRaw35) + : null, + certificateExpiresAt: map.TryGetValue("certificateExpiresAt", out var certificateExpiresAt) ? certificateExpiresAt?.ToString() : null + ); + + public Dictionary ToMap() => new Dictionary() + { + { "$id", Id }, + { "$createdAt", CreatedAt }, + { "$updatedAt", UpdatedAt }, + { "name", Name }, + { "projectId", ProjectId }, + { "rules", Rules }, + { "type", Type.Value }, + { "resourceType", ResourceType.Value }, + { "resourceId", ResourceId }, + { "window", Window }, + { "cooldown", Cooldown }, + { "enabled", Enabled }, + { "notify", Notify }, + { "escalationId", EscalationId }, + { "severity", Severity.Value }, + { "status", Status.Value }, + { "value", Value }, + { "evaluatedAt", EvaluatedAt }, + { "alertId", AlertId }, + { "triggeredAt", TriggeredAt }, + { "interval", Interval }, + { "timeout", Timeout }, + { "url", Url }, + { "method", Method?.Value }, + { "headers", Headers }, + { "body", Body }, + { "domain", Domain }, + { "record", Record?.Value }, + { "resolver", Resolver }, + { "host", Host }, + { "port", Port }, + { "tlsMode", TlsMode?.Value }, + { "result", Result?.Value }, + { "latency", Latency }, + { "code", Code }, + { "certificateExpiresAt", CertificateExpiresAt } + }; + } +} diff --git a/Appwrite/Models/MonitorList.cs b/Appwrite/Models/MonitorList.cs new file mode 100644 index 00000000..1cbaec2b --- /dev/null +++ b/Appwrite/Models/MonitorList.cs @@ -0,0 +1,40 @@ + +using System; +using System.Linq; +using System.Collections.Generic; +using System.Text.Json; +using System.Text.Json.Serialization; +using Appwrite.Enums; +using Appwrite.Extensions; + +namespace Appwrite.Models +{ + public class MonitorList + { + [JsonPropertyName("total")] + public long Total { get; private set; } + + [JsonPropertyName("monitors")] + public List Monitors { get; private set; } + + public MonitorList( + long total, + List monitors + ) + { + Total = total; + Monitors = monitors; + } + + public static MonitorList From(Dictionary map) => new MonitorList( + total: Convert.ToInt64((map.ContainsKey("total") ? map["total"] : 0)), + monitors: (map.ContainsKey("monitors") ? map["monitors"] : new List()).ConvertToList>().Select(it => Appwrite.Models.Monitor.From(map: it)).ToList() + ); + + public Dictionary ToMap() => new Dictionary() + { + { "total", Total }, + { "monitors", Monitors?.Select(it => it.ToMap()).ToList() } + }; + } +} diff --git a/Appwrite/Services/Alerts.cs b/Appwrite/Services/Alerts.cs new file mode 100644 index 00000000..f48f51fc --- /dev/null +++ b/Appwrite/Services/Alerts.cs @@ -0,0 +1,139 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Appwrite.Models; +using Appwrite.Enums; + +namespace Appwrite.Services +{ + public class Alerts : Service + { + public Alerts(Client client) : base(client) + { + } + + /// + /// Get a list of the alerts the project's monitors raised, open and resolved. + /// An alert is created when a monitor starts firing and resolved when it + /// recovers. Use queries to filter by monitor, status, type or resource, order + /// by `$createdAt` for the latest first, and `Query.search('search', term)` to + /// search alert and monitor IDs, names and metrics. + /// + /// + public Task List(List? queries = null, bool? total = null) + { + var apiPath = "/alerts"; + + var apiParameters = new Dictionary() + { + { "queries", queries }, + { "total", total } + }; + + var apiHeaders = new Dictionary() + { + { "X-Appwrite-Project", _client.GetConfig("project") }, + { "accept", "application/json" } + }; + + + static Models.AlertList Convert(Dictionary it) + { + return Models.AlertList.From(map: it); + } + + return _client.Call( + method: "GET", + path: apiPath, + headers: apiHeaders, + parameters: apiParameters.Where(it => it.Value != null).ToDictionary(it => it.Key, it => it.Value)!, + convert: Convert); + + } + + /// + /// Get an alert by its unique ID: the monitor that raised it, when it fired + /// and resolved, and the readings while it fired. + /// + /// + public Task Get(string alertId) + { + if (alertId == "") + { + throw new AppwriteException("Missing required parameter: \"alertId\""); + } + + var apiPath = "/alerts/{alertId}" + .Replace("{alertId}", Client.EncodePath(alertId)); + + var apiParameters = new Dictionary() + { + }; + + var apiHeaders = new Dictionary() + { + { "X-Appwrite-Project", _client.GetConfig("project") }, + { "accept", "application/json" } + }; + + + static Models.Alert Convert(Dictionary it) + { + return Models.Alert.From(map: it); + } + + return _client.Call( + method: "GET", + path: apiPath, + headers: apiHeaders, + parameters: apiParameters.Where(it => it.Value != null).ToDictionary(it => it.Key, it => it.Value)!, + convert: Convert); + + } + + /// + /// Acknowledge a firing alert, or undo that. Everyone who can read the alert + /// sees who acknowledged it and when. The alert keeps firing until its monitor + /// recovers; a resolved alert keeps its acknowledgement and cannot be changed. + /// + /// + public Task Update(string alertId, bool acknowledged) + { + if (alertId == "") + { + throw new AppwriteException("Missing required parameter: \"alertId\""); + } + + var apiPath = "/alerts/{alertId}" + .Replace("{alertId}", Client.EncodePath(alertId)); + + var apiParameters = new Dictionary() + { + { "acknowledged", acknowledged } + }; + + var apiHeaders = new Dictionary() + { + { "X-Appwrite-Project", _client.GetConfig("project") }, + { "content-type", "application/json" }, + { "accept", "application/json" } + }; + + + static Models.Alert Convert(Dictionary it) + { + return Models.Alert.From(map: it); + } + + return _client.Call( + method: "PATCH", + path: apiPath, + headers: apiHeaders, + parameters: apiParameters.Where(it => it.Value != null).ToDictionary(it => it.Key, it => it.Value)!, + convert: Convert); + + } + + } +} diff --git a/Appwrite/Services/Monitors.cs b/Appwrite/Services/Monitors.cs new file mode 100644 index 00000000..df1f0b5d --- /dev/null +++ b/Appwrite/Services/Monitors.cs @@ -0,0 +1,659 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Appwrite.Models; +using Appwrite.Enums; + +namespace Appwrite.Services +{ + public class Monitors : Service + { + public Monitors(Client client) : base(client) + { + } + + /// + /// Get a list of the project's monitors of every type. Use queries to filter + /// by type, resource, severity or status, and `Query.search('search', term)` + /// to search monitor IDs, names, metrics and resources. + /// + /// + public Task List(List? queries = null, bool? total = null) + { + var apiPath = "/monitors"; + + var apiParameters = new Dictionary() + { + { "queries", queries }, + { "total", total } + }; + + var apiHeaders = new Dictionary() + { + { "X-Appwrite-Project", _client.GetConfig("project") }, + { "accept", "application/json" } + }; + + + static Models.MonitorList Convert(Dictionary it) + { + return Models.MonitorList.From(map: it); + } + + return _client.Call( + method: "GET", + path: apiPath, + headers: apiHeaders, + parameters: apiParameters.Where(it => it.Value != null).ToDictionary(it => it.Key, it => it.Value)!, + convert: Convert); + + } + + /// + /// Create a DNS monitor. It asks a resolver for a domain's records of one type + /// on its own interval, and opens an alert when the resolver fails, or when + /// its rules match the answers, by default when there is no such record. Each + /// alert fires the `monitors.[monitorId].alerts.[alertId].create` event when + /// it opens and `.update` when a check passes again, for project webhooks, + /// functions and realtime, and notifies the organization's members by email + /// and in the console. + /// + /// + public Task CreateDnsMonitor(string monitorId, string name, string domain, Appwrite.Enums.MonitorRecord? record = null, string? resolver = null, List? rules = null, long? interval = null, long? timeout = null, long? cooldown = null, bool? enabled = null, List? notify = null, Appwrite.Enums.MonitorSeverity? severity = null, string? escalationId = null) + { + var apiPath = "/monitors/dns"; + + var apiParameters = new Dictionary() + { + { "monitorId", monitorId }, + { "name", name }, + { "domain", domain }, + { "record", record?.Value }, + { "resolver", resolver }, + { "rules", rules }, + { "interval", interval }, + { "timeout", timeout }, + { "cooldown", cooldown }, + { "enabled", enabled }, + { "notify", notify }, + { "severity", severity?.Value }, + { "escalationId", escalationId } + }; + + var apiHeaders = new Dictionary() + { + { "X-Appwrite-Project", _client.GetConfig("project") }, + { "content-type", "application/json" }, + { "accept", "application/json" } + }; + + + static Models.Monitor Convert(Dictionary it) + { + return Models.Monitor.From(map: it); + } + + return _client.Call( + method: "POST", + path: apiPath, + headers: apiHeaders, + parameters: apiParameters.Where(it => it.Value != null).ToDictionary(it => it.Key, it => it.Value)!, + convert: Convert); + + } + + /// + /// Update a DNS monitor by its unique ID. Only the parameters passed change; + /// the monitor's state, its last check and its open alert are kept. Passing + /// `rules` replaces all of them. + /// + /// + public Task UpdateDnsMonitor(string monitorId, string? name = null, string? domain = null, Appwrite.Enums.MonitorRecord? record = null, string? resolver = null, List? rules = null, long? interval = null, long? timeout = null, long? cooldown = null, bool? enabled = null, List? notify = null, Appwrite.Enums.MonitorSeverity? severity = null, string? escalationId = null) + { + if (monitorId == "") + { + throw new AppwriteException("Missing required parameter: \"monitorId\""); + } + + var apiPath = "/monitors/dns/{monitorId}" + .Replace("{monitorId}", Client.EncodePath(monitorId)); + + var apiParameters = new Dictionary() + { + { "name", name }, + { "domain", domain }, + { "record", record?.Value }, + { "resolver", resolver }, + { "rules", rules }, + { "interval", interval }, + { "timeout", timeout }, + { "cooldown", cooldown }, + { "enabled", enabled }, + { "notify", notify }, + { "severity", severity?.Value }, + { "escalationId", escalationId } + }; + + var apiHeaders = new Dictionary() + { + { "X-Appwrite-Project", _client.GetConfig("project") }, + { "content-type", "application/json" }, + { "accept", "application/json" } + }; + + + static Models.Monitor Convert(Dictionary it) + { + return Models.Monitor.From(map: it); + } + + return _client.Call( + method: "PATCH", + path: apiPath, + headers: apiHeaders, + parameters: apiParameters.Where(it => it.Value != null).ToDictionary(it => it.Key, it => it.Value)!, + convert: Convert); + + } + + /// + /// Create an HTTP monitor. It requests a URL on its own interval, following + /// redirects, and opens an alert when the request fails or when its rules + /// match the response, by default a status outside 2xx or the certificate of + /// an HTTPS URL about to expire. The response body is discarded as it arrives. + /// Each alert fires the `monitors.[monitorId].alerts.[alertId].create` event + /// when it opens and `.update` when a check passes again, for project + /// webhooks, functions and realtime, and notifies the organization's members + /// by email and in the console. + /// + /// + public Task CreateHttpMonitor(string monitorId, string name, string url, Appwrite.Enums.MonitorMethod? method = null, object? headers = null, string? body = null, List? rules = null, long? interval = null, long? timeout = null, long? cooldown = null, bool? enabled = null, List? notify = null, Appwrite.Enums.MonitorSeverity? severity = null, string? escalationId = null) + { + var apiPath = "/monitors/http"; + + var apiParameters = new Dictionary() + { + { "monitorId", monitorId }, + { "name", name }, + { "url", url }, + { "method", method?.Value }, + { "headers", headers }, + { "body", body }, + { "rules", rules }, + { "interval", interval }, + { "timeout", timeout }, + { "cooldown", cooldown }, + { "enabled", enabled }, + { "notify", notify }, + { "severity", severity?.Value }, + { "escalationId", escalationId } + }; + + var apiHeaders = new Dictionary() + { + { "X-Appwrite-Project", _client.GetConfig("project") }, + { "content-type", "application/json" }, + { "accept", "application/json" } + }; + + + static Models.Monitor Convert(Dictionary it) + { + return Models.Monitor.From(map: it); + } + + return _client.Call( + method: "POST", + path: apiPath, + headers: apiHeaders, + parameters: apiParameters.Where(it => it.Value != null).ToDictionary(it => it.Key, it => it.Value)!, + convert: Convert); + + } + + /// + /// Update an HTTP monitor by its unique ID. Only the parameters passed change; + /// the monitor's state, its last check and its open alert are kept. Passing + /// `rules` replaces all of them. + /// + /// + public Task UpdateHttpMonitor(string monitorId, string? name = null, string? url = null, Appwrite.Enums.MonitorMethod? method = null, object? headers = null, string? body = null, List? rules = null, long? interval = null, long? timeout = null, long? cooldown = null, bool? enabled = null, List? notify = null, Appwrite.Enums.MonitorSeverity? severity = null, string? escalationId = null) + { + if (monitorId == "") + { + throw new AppwriteException("Missing required parameter: \"monitorId\""); + } + + var apiPath = "/monitors/http/{monitorId}" + .Replace("{monitorId}", Client.EncodePath(monitorId)); + + var apiParameters = new Dictionary() + { + { "name", name }, + { "url", url }, + { "method", method?.Value }, + { "headers", headers }, + { "body", body }, + { "rules", rules }, + { "interval", interval }, + { "timeout", timeout }, + { "cooldown", cooldown }, + { "enabled", enabled }, + { "notify", notify }, + { "severity", severity?.Value }, + { "escalationId", escalationId } + }; + + var apiHeaders = new Dictionary() + { + { "X-Appwrite-Project", _client.GetConfig("project") }, + { "content-type", "application/json" }, + { "accept", "application/json" } + }; + + + static Models.Monitor Convert(Dictionary it) + { + return Models.Monitor.From(map: it); + } + + return _client.Call( + method: "PATCH", + path: apiPath, + headers: apiHeaders, + parameters: apiParameters.Where(it => it.Value != null).ToDictionary(it => it.Key, it => it.Value)!, + convert: Convert); + + } + + /// + /// Create an SMTP monitor. It reads a mail server's greeting, sends `EHLO` + /// and, as its TLS mode asks, upgrades with `STARTTLS` or speaks TLS from the + /// start, on its own interval. It opens an alert when the server cannot be + /// reached, refuses the session or fails the TLS handshake, or when its rules + /// match. It never authenticates or sends mail. Each alert fires the + /// `monitors.[monitorId].alerts.[alertId].create` event when it opens and + /// `.update` when a check passes again, for project webhooks, functions and + /// realtime, and notifies the organization's members by email and in the + /// console. + /// + /// + public Task CreateSmtpMonitor(string monitorId, string name, string host, long port, Appwrite.Enums.MonitorTlsMode? tlsMode = null, List? rules = null, long? interval = null, long? timeout = null, long? cooldown = null, bool? enabled = null, List? notify = null, Appwrite.Enums.MonitorSeverity? severity = null, string? escalationId = null) + { + var apiPath = "/monitors/smtp"; + + var apiParameters = new Dictionary() + { + { "monitorId", monitorId }, + { "name", name }, + { "host", host }, + { "port", port }, + { "tlsMode", tlsMode?.Value }, + { "rules", rules }, + { "interval", interval }, + { "timeout", timeout }, + { "cooldown", cooldown }, + { "enabled", enabled }, + { "notify", notify }, + { "severity", severity?.Value }, + { "escalationId", escalationId } + }; + + var apiHeaders = new Dictionary() + { + { "X-Appwrite-Project", _client.GetConfig("project") }, + { "content-type", "application/json" }, + { "accept", "application/json" } + }; + + + static Models.Monitor Convert(Dictionary it) + { + return Models.Monitor.From(map: it); + } + + return _client.Call( + method: "POST", + path: apiPath, + headers: apiHeaders, + parameters: apiParameters.Where(it => it.Value != null).ToDictionary(it => it.Key, it => it.Value)!, + convert: Convert); + + } + + /// + /// Update an SMTP monitor by its unique ID. Only the parameters passed change; + /// the monitor's state, its last check and its open alert are kept. Passing + /// `rules` replaces all of them. + /// + /// + public Task UpdateSmtpMonitor(string monitorId, string? name = null, string? host = null, long? port = null, Appwrite.Enums.MonitorTlsMode? tlsMode = null, List? rules = null, long? interval = null, long? timeout = null, long? cooldown = null, bool? enabled = null, List? notify = null, Appwrite.Enums.MonitorSeverity? severity = null, string? escalationId = null) + { + if (monitorId == "") + { + throw new AppwriteException("Missing required parameter: \"monitorId\""); + } + + var apiPath = "/monitors/smtp/{monitorId}" + .Replace("{monitorId}", Client.EncodePath(monitorId)); + + var apiParameters = new Dictionary() + { + { "name", name }, + { "host", host }, + { "port", port }, + { "tlsMode", tlsMode?.Value }, + { "rules", rules }, + { "interval", interval }, + { "timeout", timeout }, + { "cooldown", cooldown }, + { "enabled", enabled }, + { "notify", notify }, + { "severity", severity?.Value }, + { "escalationId", escalationId } + }; + + var apiHeaders = new Dictionary() + { + { "X-Appwrite-Project", _client.GetConfig("project") }, + { "content-type", "application/json" }, + { "accept", "application/json" } + }; + + + static Models.Monitor Convert(Dictionary it) + { + return Models.Monitor.From(map: it); + } + + return _client.Call( + method: "PATCH", + path: apiPath, + headers: apiHeaders, + parameters: apiParameters.Where(it => it.Value != null).ToDictionary(it => it.Key, it => it.Value)!, + convert: Convert); + + } + + /// + /// Create a TCP monitor. It opens a connection to a host and port on its own + /// interval and closes it at once, and opens an alert when the connection + /// cannot be made, or when its rules match. Each alert fires the + /// `monitors.[monitorId].alerts.[alertId].create` event when it opens and + /// `.update` when a check passes again, for project webhooks, functions and + /// realtime, and notifies the organization's members by email and in the + /// console. + /// + /// + public Task CreateTcpMonitor(string monitorId, string name, string host, long port, List? rules = null, long? interval = null, long? timeout = null, long? cooldown = null, bool? enabled = null, List? notify = null, Appwrite.Enums.MonitorSeverity? severity = null, string? escalationId = null) + { + var apiPath = "/monitors/tcp"; + + var apiParameters = new Dictionary() + { + { "monitorId", monitorId }, + { "name", name }, + { "host", host }, + { "port", port }, + { "rules", rules }, + { "interval", interval }, + { "timeout", timeout }, + { "cooldown", cooldown }, + { "enabled", enabled }, + { "notify", notify }, + { "severity", severity?.Value }, + { "escalationId", escalationId } + }; + + var apiHeaders = new Dictionary() + { + { "X-Appwrite-Project", _client.GetConfig("project") }, + { "content-type", "application/json" }, + { "accept", "application/json" } + }; + + + static Models.Monitor Convert(Dictionary it) + { + return Models.Monitor.From(map: it); + } + + return _client.Call( + method: "POST", + path: apiPath, + headers: apiHeaders, + parameters: apiParameters.Where(it => it.Value != null).ToDictionary(it => it.Key, it => it.Value)!, + convert: Convert); + + } + + /// + /// Update a TCP monitor by its unique ID. Only the parameters passed change; + /// the monitor's state, its last check and its open alert are kept. Passing + /// `rules` replaces all of them. + /// + /// + public Task UpdateTcpMonitor(string monitorId, string? name = null, string? host = null, long? port = null, List? rules = null, long? interval = null, long? timeout = null, long? cooldown = null, bool? enabled = null, List? notify = null, Appwrite.Enums.MonitorSeverity? severity = null, string? escalationId = null) + { + if (monitorId == "") + { + throw new AppwriteException("Missing required parameter: \"monitorId\""); + } + + var apiPath = "/monitors/tcp/{monitorId}" + .Replace("{monitorId}", Client.EncodePath(monitorId)); + + var apiParameters = new Dictionary() + { + { "name", name }, + { "host", host }, + { "port", port }, + { "rules", rules }, + { "interval", interval }, + { "timeout", timeout }, + { "cooldown", cooldown }, + { "enabled", enabled }, + { "notify", notify }, + { "severity", severity?.Value }, + { "escalationId", escalationId } + }; + + var apiHeaders = new Dictionary() + { + { "X-Appwrite-Project", _client.GetConfig("project") }, + { "content-type", "application/json" }, + { "accept", "application/json" } + }; + + + static Models.Monitor Convert(Dictionary it) + { + return Models.Monitor.From(map: it); + } + + return _client.Call( + method: "PATCH", + path: apiPath, + headers: apiHeaders, + parameters: apiParameters.Where(it => it.Value != null).ToDictionary(it => it.Key, it => it.Value)!, + convert: Convert); + + } + + /// + /// Create a usage monitor. It reads a usage metric of the project, or of one + /// of its databases, buckets, functions or sites, on a schedule, and opens an + /// alert when all its rules hold. Each alert fires the + /// `monitors.[monitorId].alerts.[alertId].create` event when it opens and + /// `.update` when usage recovers, for project webhooks, functions and + /// realtime, and notifies the confirmed members of the `notify` roles by email + /// and in the console, or the steps of the escalation set by `escalationId`. + /// + /// + public Task CreateUsageMonitor(string monitorId, string name, List rules, long? window = null, long? cooldown = null, bool? enabled = null, List? notify = null, Appwrite.Enums.MonitorSeverity? severity = null, string? escalationId = null) + { + var apiPath = "/monitors/usage"; + + var apiParameters = new Dictionary() + { + { "monitorId", monitorId }, + { "name", name }, + { "rules", rules }, + { "window", window }, + { "cooldown", cooldown }, + { "enabled", enabled }, + { "notify", notify }, + { "severity", severity?.Value }, + { "escalationId", escalationId } + }; + + var apiHeaders = new Dictionary() + { + { "X-Appwrite-Project", _client.GetConfig("project") }, + { "content-type", "application/json" }, + { "accept", "application/json" } + }; + + + static Models.Monitor Convert(Dictionary it) + { + return Models.Monitor.From(map: it); + } + + return _client.Call( + method: "POST", + path: apiPath, + headers: apiHeaders, + parameters: apiParameters.Where(it => it.Value != null).ToDictionary(it => it.Key, it => it.Value)!, + convert: Convert); + + } + + /// + /// Update a usage monitor by its unique ID. Only the parameters passed change; + /// the monitor's state and its open alert are kept. Passing `rules` replaces + /// all of them. + /// + /// + public Task UpdateUsageMonitor(string monitorId, string? name = null, List? rules = null, long? window = null, long? cooldown = null, bool? enabled = null, List? notify = null, Appwrite.Enums.MonitorSeverity? severity = null, string? escalationId = null) + { + if (monitorId == "") + { + throw new AppwriteException("Missing required parameter: \"monitorId\""); + } + + var apiPath = "/monitors/usage/{monitorId}" + .Replace("{monitorId}", Client.EncodePath(monitorId)); + + var apiParameters = new Dictionary() + { + { "name", name }, + { "rules", rules }, + { "window", window }, + { "cooldown", cooldown }, + { "enabled", enabled }, + { "notify", notify }, + { "severity", severity?.Value }, + { "escalationId", escalationId } + }; + + var apiHeaders = new Dictionary() + { + { "X-Appwrite-Project", _client.GetConfig("project") }, + { "content-type", "application/json" }, + { "accept", "application/json" } + }; + + + static Models.Monitor Convert(Dictionary it) + { + return Models.Monitor.From(map: it); + } + + return _client.Call( + method: "PATCH", + path: apiPath, + headers: apiHeaders, + parameters: apiParameters.Where(it => it.Value != null).ToDictionary(it => it.Key, it => it.Value)!, + convert: Convert); + + } + + /// + /// Get a monitor by its unique ID, with its state as of its last evaluation. + /// + /// + public Task Get(string monitorId) + { + if (monitorId == "") + { + throw new AppwriteException("Missing required parameter: \"monitorId\""); + } + + var apiPath = "/monitors/{monitorId}" + .Replace("{monitorId}", Client.EncodePath(monitorId)); + + var apiParameters = new Dictionary() + { + }; + + var apiHeaders = new Dictionary() + { + { "X-Appwrite-Project", _client.GetConfig("project") }, + { "accept", "application/json" } + }; + + + static Models.Monitor Convert(Dictionary it) + { + return Models.Monitor.From(map: it); + } + + return _client.Call( + method: "GET", + path: apiPath, + headers: apiHeaders, + parameters: apiParameters.Where(it => it.Value != null).ToDictionary(it => it.Key, it => it.Value)!, + convert: Convert); + + } + + /// + /// Delete a monitor by its unique ID. It stops being evaluated; an alert it is + /// firing is resolved and kept with the rest of its alert history. + /// + /// + public Task Delete(string monitorId) + { + if (monitorId == "") + { + throw new AppwriteException("Missing required parameter: \"monitorId\""); + } + + var apiPath = "/monitors/{monitorId}" + .Replace("{monitorId}", Client.EncodePath(monitorId)); + + var apiParameters = new Dictionary() + { + }; + + var apiHeaders = new Dictionary() + { + { "X-Appwrite-Project", _client.GetConfig("project") }, + { "content-type", "application/json" }, + { "accept", "application/json" } + }; + + + + return _client.Call( + method: "DELETE", + path: apiPath, + headers: apiHeaders, + parameters: apiParameters.Where(it => it.Value != null).ToDictionary(it => it.Key, it => it.Value)!); + + } + + } +} diff --git a/Appwrite/Services/Organization.cs b/Appwrite/Services/Organization.cs index f847e90b..b166a2bb 100644 --- a/Appwrite/Services/Organization.cs +++ b/Appwrite/Services/Organization.cs @@ -103,6 +103,208 @@ public Task Delete() + return _client.Call( + method: "DELETE", + path: apiPath, + headers: apiHeaders, + parameters: apiParameters.Where(it => it.Value != null).ToDictionary(it => it.Key, it => it.Value)!); + + } + + /// + /// Get a list of your organization's escalations. Use `Query.search('search', + /// term)` to search escalation IDs and names. + /// + /// + public Task ListEscalations(List? queries = null, bool? total = null) + { + var apiPath = "/organization/escalations"; + + var apiParameters = new Dictionary() + { + { "queries", queries }, + { "total", total } + }; + + var apiHeaders = new Dictionary() + { + { "X-Appwrite-Project", _client.GetConfig("project") }, + { "accept", "application/json" } + }; + + + static Models.EscalationList Convert(Dictionary it) + { + return Models.EscalationList.From(map: it); + } + + return _client.Call( + method: "GET", + path: apiPath, + headers: apiHeaders, + parameters: apiParameters.Where(it => it.Value != null).ToDictionary(it => it.Key, it => it.Value)!, + convert: Convert); + + } + + /// + /// Create an escalation for your organization. A monitor using it notifies the + /// escalation's steps one after another while its alert fires, each by email, + /// push and in the console, until a member acknowledges the alert or it + /// resolves. Each step waits its `delay` in seconds, after the alert fires for + /// the first step and after the previous step for the others, then notifies + /// the members holding its `roles` and those named in `userIds`. With + /// `repeat`, the steps run again from the first, a monitor's cooldown after + /// the last step. + /// + /// + public Task CreateEscalation(string escalationId, string name, List steps, long? repeat = null) + { + var apiPath = "/organization/escalations"; + + var apiParameters = new Dictionary() + { + { "escalationId", escalationId }, + { "name", name }, + { "steps", steps }, + { "repeat", repeat } + }; + + var apiHeaders = new Dictionary() + { + { "X-Appwrite-Project", _client.GetConfig("project") }, + { "content-type", "application/json" }, + { "accept", "application/json" } + }; + + + static Models.Escalation Convert(Dictionary it) + { + return Models.Escalation.From(map: it); + } + + return _client.Call( + method: "POST", + path: apiPath, + headers: apiHeaders, + parameters: apiParameters.Where(it => it.Value != null).ToDictionary(it => it.Key, it => it.Value)!, + convert: Convert); + + } + + /// + /// Get one of your organization's escalations by its ID. + /// + /// + public Task GetEscalation(string escalationId) + { + if (escalationId == "") + { + throw new AppwriteException("Missing required parameter: \"escalationId\""); + } + + var apiPath = "/organization/escalations/{escalationId}" + .Replace("{escalationId}", Client.EncodePath(escalationId)); + + var apiParameters = new Dictionary() + { + }; + + var apiHeaders = new Dictionary() + { + { "X-Appwrite-Project", _client.GetConfig("project") }, + { "accept", "application/json" } + }; + + + static Models.Escalation Convert(Dictionary it) + { + return Models.Escalation.From(map: it); + } + + return _client.Call( + method: "GET", + path: apiPath, + headers: apiHeaders, + parameters: apiParameters.Where(it => it.Value != null).ToDictionary(it => it.Key, it => it.Value)!, + convert: Convert); + + } + + /// + /// Update an escalation's name, steps or repeats; what you leave out stays as + /// it is. Alerts already escalating keep the steps they started with; the next + /// alert uses the new ones. + /// + /// + public Task UpdateEscalation(string escalationId, string? name = null, List? steps = null, long? repeat = null) + { + if (escalationId == "") + { + throw new AppwriteException("Missing required parameter: \"escalationId\""); + } + + var apiPath = "/organization/escalations/{escalationId}" + .Replace("{escalationId}", Client.EncodePath(escalationId)); + + var apiParameters = new Dictionary() + { + { "name", name }, + { "steps", steps }, + { "repeat", repeat } + }; + + var apiHeaders = new Dictionary() + { + { "X-Appwrite-Project", _client.GetConfig("project") }, + { "content-type", "application/json" }, + { "accept", "application/json" } + }; + + + static Models.Escalation Convert(Dictionary it) + { + return Models.Escalation.From(map: it); + } + + return _client.Call( + method: "PATCH", + path: apiPath, + headers: apiHeaders, + parameters: apiParameters.Where(it => it.Value != null).ToDictionary(it => it.Key, it => it.Value)!, + convert: Convert); + + } + + /// + /// Delete an escalation. An escalation that a monitor uses cannot be deleted: + /// move the monitor to another escalation or to `notify` roles first. Open + /// alerts keep the steps they started with. + /// + /// + public Task DeleteEscalation(string escalationId) + { + if (escalationId == "") + { + throw new AppwriteException("Missing required parameter: \"escalationId\""); + } + + var apiPath = "/organization/escalations/{escalationId}" + .Replace("{escalationId}", Client.EncodePath(escalationId)); + + var apiParameters = new Dictionary() + { + }; + + var apiHeaders = new Dictionary() + { + { "X-Appwrite-Project", _client.GetConfig("project") }, + { "content-type", "application/json" }, + { "accept", "application/json" } + }; + + + return _client.Call( method: "DELETE", path: apiPath, diff --git a/CHANGELOG.md b/CHANGELOG.md index 11aaed12..68a8f41d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Change Log +## 11.5.0 + +* Added: `monitors` service to create, list, get, update and delete HTTP, DNS, TCP, SMTP and usage monitors +* Added: `alerts` service to list and get alerts, and acknowledge them with `alerts.update` +* Added: `organization.listEscalations`, `createEscalation`, `getEscalation`, `updateEscalation` and `deleteEscalation` +* Added: `Monitor`, `Alert`, `Escalation` and `EscalationStep` models, their list models, and the `Monitor*` and `Alert*` enums + ## 11.4.0 * Added: `Messaging.CreateBirdEmailProvider`, `UpdateBirdEmailProvider`, `CreateBirdSMSProvider` and `UpdateBirdSMSProvider` for the Bird email and SMS providers diff --git a/README.md b/README.md index c54b7366..7af06106 100644 --- a/README.md +++ b/README.md @@ -17,19 +17,19 @@ The package targets .NET Standard 2.0 and .NET Framework 4.6.2, so it runs on .N Install it with the .NET CLI: ```bash -dotnet add package Appwrite --version 11.4.0 +dotnet add package Appwrite --version 11.5.0 ``` Or with the Package Manager Console: ```powershell -Install-Package Appwrite -Version 11.4.0 +Install-Package Appwrite -Version 11.5.0 ``` Or add a reference to your project's `.csproj` file: ```xml - + ``` ## Getting Started diff --git a/docs/examples/alerts/get.md b/docs/examples/alerts/get.md new file mode 100644 index 00000000..611ae234 --- /dev/null +++ b/docs/examples/alerts/get.md @@ -0,0 +1,17 @@ +```csharp +using Appwrite; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your secret API key + +Alerts alerts = new Alerts(client); + +Appwrite.Models.Alert result = await alerts.Get( + alertId: "" +); + +``` diff --git a/docs/examples/alerts/list.md b/docs/examples/alerts/list.md new file mode 100644 index 00000000..bc27e29d --- /dev/null +++ b/docs/examples/alerts/list.md @@ -0,0 +1,18 @@ +```csharp +using Appwrite; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your secret API key + +Alerts alerts = new Alerts(client); + +Appwrite.Models.AlertList result = await alerts.List( + queries: new List(), // optional + total: false // optional +); + +``` diff --git a/docs/examples/alerts/update.md b/docs/examples/alerts/update.md new file mode 100644 index 00000000..e8f2a94b --- /dev/null +++ b/docs/examples/alerts/update.md @@ -0,0 +1,18 @@ +```csharp +using Appwrite; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your secret API key + +Alerts alerts = new Alerts(client); + +Appwrite.Models.Alert result = await alerts.Update( + alertId: "", + acknowledged: true +); + +``` diff --git a/docs/examples/monitors/create-dns-monitor.md b/docs/examples/monitors/create-dns-monitor.md new file mode 100644 index 00000000..3f7f2de1 --- /dev/null +++ b/docs/examples/monitors/create-dns-monitor.md @@ -0,0 +1,35 @@ +```csharp +using Appwrite; +using Appwrite.Enums; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your secret API key + +Monitors monitors = new Monitors(client); + +Appwrite.Models.Monitor result = await monitors.CreateDnsMonitor( + monitorId: "", + name: "", + domain: "example.com", + record: MonitorRecord.A, // optional + resolver: "1.1.1.1", // optional + rules: new List { + Query.Or(new List { + Query.Equal("answers", 0), + Query.GreaterThan("latency", 1000) + }) + }, // optional + interval: 60, // optional + timeout: 10, // optional + cooldown: 300, // optional + enabled: true, // optional + notify: ["owner"], // optional + severity: MonitorSeverity.Info, // optional + escalationId: "" // optional +); + +``` diff --git a/docs/examples/monitors/create-http-monitor.md b/docs/examples/monitors/create-http-monitor.md new file mode 100644 index 00000000..29f5c9a2 --- /dev/null +++ b/docs/examples/monitors/create-http-monitor.md @@ -0,0 +1,36 @@ +```csharp +using Appwrite; +using Appwrite.Enums; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your secret API key + +Monitors monitors = new Monitors(client); + +Appwrite.Models.Monitor result = await monitors.CreateHttpMonitor( + monitorId: "", + name: "", + url: "https://api.example.com/health", + method: MonitorMethod.GET, // optional + headers: new { Authorization = "Bearer " }, // optional + body: "", // optional + rules: new List { + Query.Or(new List { + Query.NotBetween("statusCode", 200, 299), + Query.GreaterThan("latency", 2000) + }) + }, // optional + interval: 60, // optional + timeout: 10, // optional + cooldown: 300, // optional + enabled: true, // optional + notify: ["owner"], // optional + severity: MonitorSeverity.Info, // optional + escalationId: "" // optional +); + +``` diff --git a/docs/examples/monitors/create-smtp-monitor.md b/docs/examples/monitors/create-smtp-monitor.md new file mode 100644 index 00000000..f1929d5d --- /dev/null +++ b/docs/examples/monitors/create-smtp-monitor.md @@ -0,0 +1,35 @@ +```csharp +using Appwrite; +using Appwrite.Enums; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your secret API key + +Monitors monitors = new Monitors(client); + +Appwrite.Models.Monitor result = await monitors.CreateSmtpMonitor( + monitorId: "", + name: "", + host: "smtp.example.com", + port: 587, + tlsMode: MonitorTlsMode.None, // optional + rules: new List { + Query.Or(new List { + Query.LessThan("certificateDays", 14), + Query.GreaterThan("latency", 2000) + }) + }, // optional + interval: 60, // optional + timeout: 10, // optional + cooldown: 300, // optional + enabled: true, // optional + notify: ["owner"], // optional + severity: MonitorSeverity.Info, // optional + escalationId: "" // optional +); + +``` diff --git a/docs/examples/monitors/create-tcp-monitor.md b/docs/examples/monitors/create-tcp-monitor.md new file mode 100644 index 00000000..54a8ab0c --- /dev/null +++ b/docs/examples/monitors/create-tcp-monitor.md @@ -0,0 +1,31 @@ +```csharp +using Appwrite; +using Appwrite.Enums; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your secret API key + +Monitors monitors = new Monitors(client); + +Appwrite.Models.Monitor result = await monitors.CreateTcpMonitor( + monitorId: "", + name: "", + host: "db.example.com", + port: 5432, + rules: new List { + Query.GreaterThan("latency", 1000) + }, // optional + interval: 60, // optional + timeout: 10, // optional + cooldown: 300, // optional + enabled: true, // optional + notify: ["owner"], // optional + severity: MonitorSeverity.Info, // optional + escalationId: "" // optional +); + +``` diff --git a/docs/examples/monitors/create-usage-monitor.md b/docs/examples/monitors/create-usage-monitor.md new file mode 100644 index 00000000..bc6b7453 --- /dev/null +++ b/docs/examples/monitors/create-usage-monitor.md @@ -0,0 +1,28 @@ +```csharp +using Appwrite; +using Appwrite.Enums; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your secret API key + +Monitors monitors = new Monitors(client); + +Appwrite.Models.Monitor result = await monitors.CreateUsageMonitor( + monitorId: "", + name: "", + rules: new List { + Query.GreaterThan("network.outbound", 5000000000) + }, + window: 3600, // optional + cooldown: 1800, // optional + enabled: true, // optional + notify: ["owner"], // optional + severity: MonitorSeverity.Info, // optional + escalationId: "" // optional +); + +``` diff --git a/docs/examples/monitors/delete.md b/docs/examples/monitors/delete.md new file mode 100644 index 00000000..7e364df1 --- /dev/null +++ b/docs/examples/monitors/delete.md @@ -0,0 +1,17 @@ +```csharp +using Appwrite; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your secret API key + +Monitors monitors = new Monitors(client); + +await monitors.Delete( + monitorId: "" +); + +``` diff --git a/docs/examples/monitors/get.md b/docs/examples/monitors/get.md new file mode 100644 index 00000000..6fe93c3e --- /dev/null +++ b/docs/examples/monitors/get.md @@ -0,0 +1,17 @@ +```csharp +using Appwrite; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your secret API key + +Monitors monitors = new Monitors(client); + +Appwrite.Models.Monitor result = await monitors.Get( + monitorId: "" +); + +``` diff --git a/docs/examples/monitors/list.md b/docs/examples/monitors/list.md new file mode 100644 index 00000000..63075256 --- /dev/null +++ b/docs/examples/monitors/list.md @@ -0,0 +1,18 @@ +```csharp +using Appwrite; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your secret API key + +Monitors monitors = new Monitors(client); + +Appwrite.Models.MonitorList result = await monitors.List( + queries: new List(), // optional + total: false // optional +); + +``` diff --git a/docs/examples/monitors/update-dns-monitor.md b/docs/examples/monitors/update-dns-monitor.md new file mode 100644 index 00000000..f7cf0932 --- /dev/null +++ b/docs/examples/monitors/update-dns-monitor.md @@ -0,0 +1,35 @@ +```csharp +using Appwrite; +using Appwrite.Enums; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your secret API key + +Monitors monitors = new Monitors(client); + +Appwrite.Models.Monitor result = await monitors.UpdateDnsMonitor( + monitorId: "", + name: "", // optional + domain: "example.com", // optional + record: MonitorRecord.A, // optional + resolver: "1.1.1.1", // optional + rules: new List { + Query.Or(new List { + Query.Equal("answers", 0), + Query.GreaterThan("latency", 1000) + }) + }, // optional + interval: 60, // optional + timeout: 10, // optional + cooldown: 300, // optional + enabled: true, // optional + notify: ["owner"], // optional + severity: MonitorSeverity.Info, // optional + escalationId: "" // optional +); + +``` diff --git a/docs/examples/monitors/update-http-monitor.md b/docs/examples/monitors/update-http-monitor.md new file mode 100644 index 00000000..47873e43 --- /dev/null +++ b/docs/examples/monitors/update-http-monitor.md @@ -0,0 +1,36 @@ +```csharp +using Appwrite; +using Appwrite.Enums; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your secret API key + +Monitors monitors = new Monitors(client); + +Appwrite.Models.Monitor result = await monitors.UpdateHttpMonitor( + monitorId: "", + name: "", // optional + url: "https://api.example.com/health", // optional + method: MonitorMethod.GET, // optional + headers: new { Authorization = "Bearer " }, // optional + body: "", // optional + rules: new List { + Query.Or(new List { + Query.NotBetween("statusCode", 200, 299), + Query.GreaterThan("latency", 2000) + }) + }, // optional + interval: 60, // optional + timeout: 10, // optional + cooldown: 300, // optional + enabled: true, // optional + notify: ["owner"], // optional + severity: MonitorSeverity.Info, // optional + escalationId: "" // optional +); + +``` diff --git a/docs/examples/monitors/update-smtp-monitor.md b/docs/examples/monitors/update-smtp-monitor.md new file mode 100644 index 00000000..245cba30 --- /dev/null +++ b/docs/examples/monitors/update-smtp-monitor.md @@ -0,0 +1,35 @@ +```csharp +using Appwrite; +using Appwrite.Enums; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your secret API key + +Monitors monitors = new Monitors(client); + +Appwrite.Models.Monitor result = await monitors.UpdateSmtpMonitor( + monitorId: "", + name: "", // optional + host: "smtp.example.com", // optional + port: 587, // optional + tlsMode: MonitorTlsMode.None, // optional + rules: new List { + Query.Or(new List { + Query.LessThan("certificateDays", 14), + Query.GreaterThan("latency", 2000) + }) + }, // optional + interval: 60, // optional + timeout: 10, // optional + cooldown: 300, // optional + enabled: true, // optional + notify: ["owner"], // optional + severity: MonitorSeverity.Info, // optional + escalationId: "" // optional +); + +``` diff --git a/docs/examples/monitors/update-tcp-monitor.md b/docs/examples/monitors/update-tcp-monitor.md new file mode 100644 index 00000000..5964031a --- /dev/null +++ b/docs/examples/monitors/update-tcp-monitor.md @@ -0,0 +1,31 @@ +```csharp +using Appwrite; +using Appwrite.Enums; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your secret API key + +Monitors monitors = new Monitors(client); + +Appwrite.Models.Monitor result = await monitors.UpdateTcpMonitor( + monitorId: "", + name: "", // optional + host: "db.example.com", // optional + port: 5432, // optional + rules: new List { + Query.GreaterThan("latency", 1000) + }, // optional + interval: 60, // optional + timeout: 10, // optional + cooldown: 300, // optional + enabled: true, // optional + notify: ["owner"], // optional + severity: MonitorSeverity.Info, // optional + escalationId: "" // optional +); + +``` diff --git a/docs/examples/monitors/update-usage-monitor.md b/docs/examples/monitors/update-usage-monitor.md new file mode 100644 index 00000000..860ea2eb --- /dev/null +++ b/docs/examples/monitors/update-usage-monitor.md @@ -0,0 +1,28 @@ +```csharp +using Appwrite; +using Appwrite.Enums; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your secret API key + +Monitors monitors = new Monitors(client); + +Appwrite.Models.Monitor result = await monitors.UpdateUsageMonitor( + monitorId: "", + name: "", // optional + rules: new List { + Query.GreaterThan("network.outbound", 5000000000) + }, // optional + window: 3600, // optional + cooldown: 1800, // optional + enabled: true, // optional + notify: ["owner"], // optional + severity: MonitorSeverity.Info, // optional + escalationId: "" // optional +); + +``` diff --git a/docs/examples/organization/create-escalation.md b/docs/examples/organization/create-escalation.md new file mode 100644 index 00000000..950e2092 --- /dev/null +++ b/docs/examples/organization/create-escalation.md @@ -0,0 +1,33 @@ +```csharp +using Appwrite; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your secret API key + +Organization organization = new Organization(client); + +Appwrite.Models.Escalation result = await organization.CreateEscalation( + escalationId: "", + name: "", + steps: new List + { + new Dictionary + { + { "delay", 0 }, + { "roles", new List { "owner" } } + }, + new Dictionary + { + { "delay", 900 }, + { "roles", new List { "developer" } }, + { "userIds", new List { "" } } + } + }, + repeat: 1 // optional +); + +``` diff --git a/docs/examples/organization/delete-escalation.md b/docs/examples/organization/delete-escalation.md new file mode 100644 index 00000000..cba31c0f --- /dev/null +++ b/docs/examples/organization/delete-escalation.md @@ -0,0 +1,17 @@ +```csharp +using Appwrite; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your secret API key + +Organization organization = new Organization(client); + +await organization.DeleteEscalation( + escalationId: "" +); + +``` diff --git a/docs/examples/organization/get-escalation.md b/docs/examples/organization/get-escalation.md new file mode 100644 index 00000000..7599776a --- /dev/null +++ b/docs/examples/organization/get-escalation.md @@ -0,0 +1,17 @@ +```csharp +using Appwrite; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your secret API key + +Organization organization = new Organization(client); + +Appwrite.Models.Escalation result = await organization.GetEscalation( + escalationId: "" +); + +``` diff --git a/docs/examples/organization/list-escalations.md b/docs/examples/organization/list-escalations.md new file mode 100644 index 00000000..7e29d0c2 --- /dev/null +++ b/docs/examples/organization/list-escalations.md @@ -0,0 +1,18 @@ +```csharp +using Appwrite; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your secret API key + +Organization organization = new Organization(client); + +Appwrite.Models.EscalationList result = await organization.ListEscalations( + queries: new List(), // optional + total: false // optional +); + +``` diff --git a/docs/examples/organization/update-escalation.md b/docs/examples/organization/update-escalation.md new file mode 100644 index 00000000..9b540b54 --- /dev/null +++ b/docs/examples/organization/update-escalation.md @@ -0,0 +1,33 @@ +```csharp +using Appwrite; +using Appwrite.Models; +using Appwrite.Services; + +Client client = new Client() + .SetEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .SetProject("") // Your project ID + .SetKey(""); // Your secret API key + +Organization organization = new Organization(client); + +Appwrite.Models.Escalation result = await organization.UpdateEscalation( + escalationId: "", + name: "", // optional + steps: new List + { + new Dictionary + { + { "delay", 0 }, + { "roles", new List { "owner" } } + }, + new Dictionary + { + { "delay", 900 }, + { "roles", new List { "developer" } }, + { "userIds", new List { "" } } + } + }, // optional + repeat: 1 // optional +); + +```