Edits history of script submission #5289 for ' Create a Notification policy (cloudflare)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Cloudflare = {
      token: string;
      email: string;
      key: string;
    };
    /**
     * Create a Notification policy
     * Creates a new Notification policy.
     */
    export async function main(
      auth: Cloudflare,
      account_id: string,
      body: {
        alert_type:
          | "access_custom_certificate_expiration_type"
          | "advanced_ddos_attack_l4_alert"
          | "advanced_ddos_attack_l7_alert"
          | "advanced_http_alert_error"
          | "bgp_hijack_notification"
          | "billing_usage_alert"
          | "block_notification_block_removed"
          | "block_notification_new_block"
          | "block_notification_review_rejected"
          | "brand_protection_alert"
          | "brand_protection_digest"
          | "clickhouse_alert_fw_anomaly"
          | "clickhouse_alert_fw_ent_anomaly"
          | "custom_ssl_certificate_event_type"
          | "dedicated_ssl_certificate_event_type"
          | "dos_attack_l4"
          | "dos_attack_l7"
          | "expiring_service_token_alert"
          | "failing_logpush_job_disabled_alert"
          | "fbm_auto_advertisement"
          | "fbm_dosd_attack"
          | "fbm_volumetric_attack"
          | "health_check_status_notification"
          | "hostname_aop_custom_certificate_expiration_type"
          | "http_alert_edge_error"
          | "http_alert_origin_error"
          | "incident_alert"
          | "load_balancing_health_alert"
          | "load_balancing_pool_enablement_alert"
          | "logo_match_alert"
          | "magic_tunnel_health_check_event"
          | "maintenance_event_notification"
          | "mtls_certificate_store_certificate_expiration_type"
          | "pages_event_alert"
          | "radar_notification"
          | "real_origin_monitoring"
          | "scriptmonitor_alert_new_code_change_detections"
          | "scriptmonitor_alert_new_hosts"
          | "scriptmonitor_alert_new_malicious_hosts"
          | "scriptmonitor_alert_new_malicious_scripts"
          | "scriptmonitor_alert_new_malicious_url"
          | "scriptmonitor_alert_new_max_length_resource_url"
          | "scriptmonitor_alert_new_resources"
          | "secondary_dns_all_primaries_failing"
          | "secondary_dns_primaries_failing"
          | "secondary_dns_zone_successfully_updated"
          | "secondary_dns_zone_validation_warning"
          | "sentinel_alert"
          | "stream_live_notifications"
          | "tunnel_health_event"
          | "tunnel_update_event"
          | "universal_ssl_event_type"
          | "web_analytics_metrics_update"
          | "zone_aop_custom_certificate_expiration_type";
        description?: string;
        enabled: boolean;
        filters?: {
          actions?: string[];
          affected_asns?: string[];
          affected_components?: string[];
          affected_locations?: string[];
          airport_code?: string[];
          alert_trigger_preferences?: string[];
          alert_trigger_preferences_value?: ("99.0" | "98.0" | "97.0")[];
          enabled?: string[];
          environment?: string[];
          event?: string[];
          event_source?: string[];
          event_type?: string[];
          group_by?: string[];
          health_check_id?: string[];
          incident_impact?: (
            | "INCIDENT_IMPACT_NONE"
            | "INCIDENT_IMPACT_MINOR"
            | "INCIDENT_IMPACT_MAJOR"
            | "INCIDENT_IMPACT_CRITICAL"
          )[];
          input_id?: string[];
          limit?: string[];
          logo_tag?: string[];
          megabits_per_second?: string[];
          new_health?: string[];
          new_status?: string[];
          packets_per_second?: string[];
          pool_id?: string[];
          product?: string[];
          project_id?: string[];
          protocol?: string[];
          query_tag?: string[];
          requests_per_second?: string[];
          selectors?: string[];
          services?: string[];
          slo?: string[];
          status?: string[];
          target_hostname?: string[];
          target_ip?: string[];
          target_zone_name?: string[];
          traffic_exclusions?: "security_events"[];
          tunnel_id?: string[];
          tunnel_name?: string[];
          where?: string[];
          zones?: string[];
          [k: string]: unknown;
        };
        mechanisms: {
          [k: string]: { id?: string | string; [k: string]: unknown }[];
        };
        name: string;
        [k: string]: unknown;
      }
    ) {
      const url = new URL(
        `https://api.cloudflare.com/client/v4/accounts/${account_id}/alerting/v3/policies`
      );
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "X-AUTH-EMAIL": auth.email,
          "X-AUTH-KEY": auth.key,
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 383 days ago

  • nativets
    type Cloudflare = {
      token: string;
      email: string;
      key: string;
    };
    /**
     * Create a Notification policy
     * Creates a new Notification policy.
     */
    export async function main(
      auth: Cloudflare,
      account_id: string,
      body: {
        alert_type:
          | "access_custom_certificate_expiration_type"
          | "advanced_ddos_attack_l4_alert"
          | "advanced_ddos_attack_l7_alert"
          | "advanced_http_alert_error"
          | "bgp_hijack_notification"
          | "billing_usage_alert"
          | "block_notification_block_removed"
          | "block_notification_new_block"
          | "block_notification_review_rejected"
          | "brand_protection_alert"
          | "brand_protection_digest"
          | "clickhouse_alert_fw_anomaly"
          | "clickhouse_alert_fw_ent_anomaly"
          | "custom_ssl_certificate_event_type"
          | "dedicated_ssl_certificate_event_type"
          | "dos_attack_l4"
          | "dos_attack_l7"
          | "expiring_service_token_alert"
          | "failing_logpush_job_disabled_alert"
          | "fbm_auto_advertisement"
          | "fbm_dosd_attack"
          | "fbm_volumetric_attack"
          | "health_check_status_notification"
          | "hostname_aop_custom_certificate_expiration_type"
          | "http_alert_edge_error"
          | "http_alert_origin_error"
          | "incident_alert"
          | "load_balancing_health_alert"
          | "load_balancing_pool_enablement_alert"
          | "logo_match_alert"
          | "magic_tunnel_health_check_event"
          | "maintenance_event_notification"
          | "mtls_certificate_store_certificate_expiration_type"
          | "pages_event_alert"
          | "radar_notification"
          | "real_origin_monitoring"
          | "scriptmonitor_alert_new_code_change_detections"
          | "scriptmonitor_alert_new_hosts"
          | "scriptmonitor_alert_new_malicious_hosts"
          | "scriptmonitor_alert_new_malicious_scripts"
          | "scriptmonitor_alert_new_malicious_url"
          | "scriptmonitor_alert_new_max_length_resource_url"
          | "scriptmonitor_alert_new_resources"
          | "secondary_dns_all_primaries_failing"
          | "secondary_dns_primaries_failing"
          | "secondary_dns_zone_successfully_updated"
          | "secondary_dns_zone_validation_warning"
          | "sentinel_alert"
          | "stream_live_notifications"
          | "tunnel_health_event"
          | "tunnel_update_event"
          | "universal_ssl_event_type"
          | "web_analytics_metrics_update"
          | "zone_aop_custom_certificate_expiration_type";
        description?: string;
        enabled: boolean;
        filters?: {
          actions?: string[];
          affected_asns?: string[];
          affected_components?: string[];
          affected_locations?: string[];
          airport_code?: string[];
          alert_trigger_preferences?: string[];
          alert_trigger_preferences_value?: ("99.0" | "98.0" | "97.0")[];
          enabled?: string[];
          environment?: string[];
          event?: string[];
          event_source?: string[];
          event_type?: string[];
          group_by?: string[];
          health_check_id?: string[];
          incident_impact?: (
            | "INCIDENT_IMPACT_NONE"
            | "INCIDENT_IMPACT_MINOR"
            | "INCIDENT_IMPACT_MAJOR"
            | "INCIDENT_IMPACT_CRITICAL"
          )[];
          input_id?: string[];
          limit?: string[];
          logo_tag?: string[];
          megabits_per_second?: string[];
          new_health?: string[];
          new_status?: string[];
          packets_per_second?: string[];
          pool_id?: string[];
          product?: string[];
          project_id?: string[];
          protocol?: string[];
          query_tag?: string[];
          requests_per_second?: string[];
          selectors?: string[];
          services?: string[];
          slo?: string[];
          status?: string[];
          target_hostname?: string[];
          target_ip?: string[];
          target_zone_name?: string[];
          traffic_exclusions?: "security_events"[];
          tunnel_id?: string[];
          tunnel_name?: string[];
          where?: string[];
          zones?: string[];
          [k: string]: unknown;
        };
        mechanisms: {
          [k: string]: { id?: string | string; [k: string]: unknown }[];
        };
        name: string;
        [k: string]: unknown;
      }
    ) {
      const url = new URL(
        `https://api.cloudflare.com/client/v4/accounts/${account_id}/alerting/v3/policies`
      );
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "X-AUTH-EMAIL": auth.email,
          "X-AUTH-KEY": auth.key,
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 920 days ago