const fetch = require('node-fetch');
let url = 'https://api.coralogix.com/mgmt/openapi/v3/alert-defs';
let options = {
method: 'POST',
headers: {Authorization: 'Bearer <API_KEY>', 'content-type': 'application/json'},
body: '{"name":"My Alert","description":"Alert description","enabled":true,"priority":"ALERT_DEF_PRIORITY_P5_OR_UNSPECIFIED","activeOn":{"dayOfWeek":["DAY_OF_WEEK_MONDAY_OR_UNSPECIFIED","DAY_OF_WEEK_TUESDAY"],"startTime":{"hours":14,"minutes":30},"endTime":{"hours":14,"minutes":30}},"type":"ALERT_DEF_TYPE_LOGS_IMMEDIATE_OR_UNSPECIFIED","logsImmediate":{"logsFilter":{"simpleFilter":{"luceneQuery":"string","labelFilters":{"applicationName":[{"value":"my-app","operation":"LOG_FILTER_OPERATION_TYPE_IS_OR_UNSPECIFIED"}],"subsystemName":[{"value":"my-app","operation":"LOG_FILTER_OPERATION_TYPE_IS_OR_UNSPECIFIED"}],"severities":["LOG_SEVERITY_VERBOSE_UNSPECIFIED"]}}},"notificationPayloadFilter":["obj.field"]},"tracingImmediate":{"tracingFilter":{"simpleFilter":{"tracingLabelFilters":{"applicationName":[{"values":["value1","value2"],"operation":"TRACING_FILTER_OPERATION_TYPE_IS_OR_UNSPECIFIED"}],"subsystemName":[{"values":["value1","value2"],"operation":"TRACING_FILTER_OPERATION_TYPE_IS_OR_UNSPECIFIED"}],"serviceName":[{"values":["value1","value2"],"operation":"TRACING_FILTER_OPERATION_TYPE_IS_OR_UNSPECIFIED"}],"operationName":[{"values":["value1","value2"],"operation":"TRACING_FILTER_OPERATION_TYPE_IS_OR_UNSPECIFIED"}],"spanFields":[{"key":"span.field.key","filterType":{"values":["value1","value2"],"operation":"TRACING_FILTER_OPERATION_TYPE_IS_OR_UNSPECIFIED"}}]},"latencyThresholdMs":1000}},"notificationPayloadFilter":["obj.field"]},"logsThreshold":{"logsFilter":{"simpleFilter":{"luceneQuery":"string","labelFilters":{"applicationName":[{"value":"my-app","operation":"LOG_FILTER_OPERATION_TYPE_IS_OR_UNSPECIFIED"}],"subsystemName":[{"value":"my-app","operation":"LOG_FILTER_OPERATION_TYPE_IS_OR_UNSPECIFIED"}],"severities":["LOG_SEVERITY_VERBOSE_UNSPECIFIED"]}}},"undetectedValuesManagement":{"triggerUndetectedValues":true,"autoRetireTimeframe":"AUTO_RETIRE_TIMEFRAME_NEVER_OR_UNSPECIFIED"},"rules":[{"condition":{"threshold":100,"timeWindow":{"logsTimeWindowSpecificValue":"LOGS_TIME_WINDOW_VALUE_MINUTES_5_OR_UNSPECIFIED"},"conditionType":"LOGS_THRESHOLD_CONDITION_TYPE_MORE_THAN_OR_UNSPECIFIED"},"override":{"priority":"ALERT_DEF_PRIORITY_P5_OR_UNSPECIFIED"}}],"notificationPayloadFilter":["obj.field"],"evaluationDelayMs":60000},"logsRatioThreshold":{"numerator":{"simpleFilter":{"luceneQuery":"string","labelFilters":{"applicationName":[{"value":"my-app","operation":"LOG_FILTER_OPERATION_TYPE_IS_OR_UNSPECIFIED"}],"subsystemName":[{"value":"my-app","operation":"LOG_FILTER_OPERATION_TYPE_IS_OR_UNSPECIFIED"}],"severities":["LOG_SEVERITY_VERBOSE_UNSPECIFIED"]}}},"numeratorAlias":"numerator_alias","denominator":{"simpleFilter":{"luceneQuery":"string","labelFilters":{"applicationName":[{"value":"my-app","operation":"LOG_FILTER_OPERATION_TYPE_IS_OR_UNSPECIFIED"}],"subsystemName":[{"value":"my-app","operation":"LOG_FILTER_OPERATION_TYPE_IS_OR_UNSPECIFIED"}],"severities":["LOG_SEVERITY_VERBOSE_UNSPECIFIED"]}}},"denominatorAlias":"denominator_alias","rules":[{"condition":{"threshold":10,"timeWindow":{"logsRatioTimeWindowSpecificValue":"LOGS_RATIO_TIME_WINDOW_VALUE_MINUTES_5_OR_UNSPECIFIED"},"conditionType":"LOGS_RATIO_CONDITION_TYPE_MORE_THAN_OR_UNSPECIFIED"},"override":{"priority":"ALERT_DEF_PRIORITY_P5_OR_UNSPECIFIED"}}],"notificationPayloadFilter":["obj.field"],"groupByFor":"LOGS_RATIO_GROUP_BY_FOR_BOTH_OR_UNSPECIFIED","undetectedValuesManagement":{"triggerUndetectedValues":true,"autoRetireTimeframe":"AUTO_RETIRE_TIMEFRAME_NEVER_OR_UNSPECIFIED"},"ignoreInfinity":true,"evaluationDelayMs":60000},"logsTimeRelativeThreshold":{"logsFilter":{"simpleFilter":{"luceneQuery":"string","labelFilters":{"applicationName":[{"value":"my-app","operation":"LOG_FILTER_OPERATION_TYPE_IS_OR_UNSPECIFIED"}],"subsystemName":[{"value":"my-app","operation":"LOG_FILTER_OPERATION_TYPE_IS_OR_UNSPECIFIED"}],"severities":["LOG_SEVERITY_VERBOSE_UNSPECIFIED"]}}},"rules":[{"condition":{"threshold":0.1,"comparedTo":"LOGS_TIME_RELATIVE_COMPARED_TO_PREVIOUS_HOUR_OR_UNSPECIFIED","conditionType":"LOGS_TIME_RELATIVE_CONDITION_TYPE_MORE_THAN_OR_UNSPECIFIED"},"override":{"priority":"ALERT_DEF_PRIORITY_P5_OR_UNSPECIFIED"}}],"ignoreInfinity":true,"notificationPayloadFilter":["obj.field"],"undetectedValuesManagement":{"triggerUndetectedValues":true,"autoRetireTimeframe":"AUTO_RETIRE_TIMEFRAME_NEVER_OR_UNSPECIFIED"},"evaluationDelayMs":60000},"metricThreshold":{"metricFilter":{"promql":"avg_over_time(metric_name[5m]) > 10"},"rules":[{"condition":{"threshold":100,"forOverPct":80,"ofTheLast":{"metricTimeWindowSpecificValue":"METRIC_TIME_WINDOW_VALUE_MINUTES_1_OR_UNSPECIFIED","metricTimeWindowDynamicDuration":"1h30m"},"conditionType":"METRIC_THRESHOLD_CONDITION_TYPE_MORE_THAN_OR_UNSPECIFIED"},"override":{"priority":"ALERT_DEF_PRIORITY_P5_OR_UNSPECIFIED"}}],"undetectedValuesManagement":{"triggerUndetectedValues":true,"autoRetireTimeframe":"AUTO_RETIRE_TIMEFRAME_NEVER_OR_UNSPECIFIED"},"missingValues":{"replaceWithZero":true,"minNonNullValuesPct":80},"evaluationDelayMs":60000},"tracingThreshold":{"tracingFilter":{"simpleFilter":{"tracingLabelFilters":{"applicationName":[{"values":["value1","value2"],"operation":"TRACING_FILTER_OPERATION_TYPE_IS_OR_UNSPECIFIED"}],"subsystemName":[{"values":["value1","value2"],"operation":"TRACING_FILTER_OPERATION_TYPE_IS_OR_UNSPECIFIED"}],"serviceName":[{"values":["value1","value2"],"operation":"TRACING_FILTER_OPERATION_TYPE_IS_OR_UNSPECIFIED"}],"operationName":[{"values":["value1","value2"],"operation":"TRACING_FILTER_OPERATION_TYPE_IS_OR_UNSPECIFIED"}],"spanFields":[{"key":"span.field.key","filterType":{"values":["value1","value2"],"operation":"TRACING_FILTER_OPERATION_TYPE_IS_OR_UNSPECIFIED"}}]},"latencyThresholdMs":1000}},"rules":[{"condition":{"spanAmount":100,"timeWindow":{"tracingTimeWindowValue":"TRACING_TIME_WINDOW_VALUE_MINUTES_5_OR_UNSPECIFIED"},"conditionType":"TRACING_THRESHOLD_CONDITION_TYPE_MORE_THAN_OR_UNSPECIFIED"}}],"notificationPayloadFilter":["obj.field"]},"flow":{"stages":[{"flowStagesGroups":{"groups":[{"alertDefs":[{"id":"123e4567-e89b-12d3-a456-426614174000","not":true}],"nextOp":"NEXT_OP_AND_OR_UNSPECIFIED","alertsOp":"ALERTS_OP_AND_OR_UNSPECIFIED"}]},"timeframeMs":"string","timeframeType":"TIMEFRAME_TYPE_UNSPECIFIED"}],"enforceSuppression":true},"logsAnomaly":{"logsFilter":{"simpleFilter":{"luceneQuery":"string","labelFilters":{"applicationName":[{"value":"my-app","operation":"LOG_FILTER_OPERATION_TYPE_IS_OR_UNSPECIFIED"}],"subsystemName":[{"value":"my-app","operation":"LOG_FILTER_OPERATION_TYPE_IS_OR_UNSPECIFIED"}],"severities":["LOG_SEVERITY_VERBOSE_UNSPECIFIED"]}}},"rules":[{"condition":{"minimumThreshold":10,"timeWindow":{"logsTimeWindowSpecificValue":"LOGS_TIME_WINDOW_VALUE_MINUTES_5_OR_UNSPECIFIED"},"conditionType":"LOGS_ANOMALY_CONDITION_TYPE_MORE_THAN_USUAL_OR_UNSPECIFIED"}}],"notificationPayloadFilter":["obj.field"],"evaluationDelayMs":60000,"anomalyAlertSettings":{"percentageOfDeviation":0.1}},"metricAnomaly":{"metricFilter":{"promql":"avg_over_time(metric_name[5m]) > 10"},"rules":[{"condition":{"threshold":10,"forOverPct":20,"ofTheLast":{"metricTimeWindowSpecificValue":"METRIC_TIME_WINDOW_VALUE_MINUTES_1_OR_UNSPECIFIED","metricTimeWindowDynamicDuration":"1h30m"},"minNonNullValuesPct":10,"conditionType":"METRIC_ANOMALY_CONDITION_TYPE_MORE_THAN_USUAL_OR_UNSPECIFIED"}}],"evaluationDelayMs":60000,"anomalyAlertSettings":{"percentageOfDeviation":0.1}},"logsNewValue":{"logsFilter":{"simpleFilter":{"luceneQuery":"string","labelFilters":{"applicationName":[{"value":"my-app","operation":"LOG_FILTER_OPERATION_TYPE_IS_OR_UNSPECIFIED"}],"subsystemName":[{"value":"my-app","operation":"LOG_FILTER_OPERATION_TYPE_IS_OR_UNSPECIFIED"}],"severities":["LOG_SEVERITY_VERBOSE_UNSPECIFIED"]}}},"rules":[{"condition":{"keypathToTrack":"metadata.field","timeWindow":{"logsNewValueTimeWindowSpecificValue":"LOGS_NEW_VALUE_TIME_WINDOW_VALUE_HOURS_12_OR_UNSPECIFIED"}}}],"notificationPayloadFilter":["obj.field"]},"logsUniqueCount":{"logsFilter":{"simpleFilter":{"luceneQuery":"string","labelFilters":{"applicationName":[{"value":"my-app","operation":"LOG_FILTER_OPERATION_TYPE_IS_OR_UNSPECIFIED"}],"subsystemName":[{"value":"my-app","operation":"LOG_FILTER_OPERATION_TYPE_IS_OR_UNSPECIFIED"}],"severities":["LOG_SEVERITY_VERBOSE_UNSPECIFIED"]}}},"rules":[{"condition":{"maxUniqueCount":100,"timeWindow":{"logsUniqueValueTimeWindowSpecificValue":"LOGS_UNIQUE_VALUE_TIME_WINDOW_VALUE_MINUTE_1_OR_UNSPECIFIED"}}}],"notificationPayloadFilter":["obj.field"],"maxUniqueCountPerGroupByKey":100,"uniqueCountKeypath":"obj.field"},"sloThreshold":{"sloDefinition":{"sloId":"123e4567-e89b-12d3-a456-426614174000"},"errorBudget":{"rules":[{"condition":{"threshold":0.1},"override":{"priority":"ALERT_DEF_PRIORITY_P5_OR_UNSPECIFIED"}}]},"burnRate":{"rules":[{"condition":{"threshold":0.1},"override":{"priority":"ALERT_DEF_PRIORITY_P5_OR_UNSPECIFIED"}}],"dual":{"timeDuration":{"duration":60,"unit":"DURATION_UNIT_UNSPECIFIED"}},"single":{"timeDuration":{"duration":60,"unit":"DURATION_UNIT_UNSPECIFIED"}}}},"groupByKeys":["key1","key2"],"incidentsSettings":{"minutes":30,"notifyOn":"NOTIFY_ON_TRIGGERED_ONLY_UNSPECIFIED"},"notificationGroup":{"groupByKeys":["key1","key2"],"webhooks":[{"minutes":15,"notifyOn":"NOTIFY_ON_TRIGGERED_ONLY_UNSPECIFIED","integration":{"integrationId":123,"recipients":{"emails":["mail@gmail.com"]}}}],"destinations":[{"connectorId":"connector_id_example","presetId":"preset_id_example","notifyOn":"NOTIFY_ON_TRIGGERED_ONLY_UNSPECIFIED","triggeredRoutingOverrides":{"configOverrides":{"payloadType":"slack_raw, slack_structured, pagerduty_triggered, pagerduty_resolved, generic_https_default","messageConfigFields":[{"fieldName":"description","template":"template_example"}],"connectorConfigFields":[{"fieldName":"description","template":"template_example"}]}},"resolvedRouteOverrides":{"configOverrides":{"payloadType":"slack_raw, slack_structured, pagerduty_triggered, pagerduty_resolved, generic_https_default","messageConfigFields":[{"fieldName":"description","template":"template_example"}],"connectorConfigFields":[{"fieldName":"description","template":"template_example"}]}}}],"router":{"id":"123e4567-e89b-12d3-a456-426614174000","notifyOn":"NOTIFY_ON_TRIGGERED_ONLY_UNSPECIFIED"}},"notificationGroupExcess":[{"groupByKeys":["key1","key2"],"webhooks":[{"minutes":15,"notifyOn":"NOTIFY_ON_TRIGGERED_ONLY_UNSPECIFIED","integration":{"integrationId":123,"recipients":{"emails":["mail@gmail.com"]}}}],"destinations":[{"connectorId":"connector_id_example","presetId":"preset_id_example","notifyOn":"NOTIFY_ON_TRIGGERED_ONLY_UNSPECIFIED","triggeredRoutingOverrides":{"configOverrides":{"payloadType":"slack_raw, slack_structured, pagerduty_triggered, pagerduty_resolved, generic_https_default","messageConfigFields":[{"fieldName":"description","template":"template_example"}],"connectorConfigFields":[{"fieldName":"description","template":"template_example"}]}},"resolvedRouteOverrides":{"configOverrides":{"payloadType":"slack_raw, slack_structured, pagerduty_triggered, pagerduty_resolved, generic_https_default","messageConfigFields":[{"fieldName":"description","template":"template_example"}],"connectorConfigFields":[{"fieldName":"description","template":"template_example"}]}}}],"router":{"id":"123e4567-e89b-12d3-a456-426614174000","notifyOn":"NOTIFY_ON_TRIGGERED_ONLY_UNSPECIFIED"}}],"entityLabels":{"key":"value"},"phantomMode":false,"deleted":false}'
};
fetch(url, options)
.then(res => res.json())
.then(json => console.log(json))
.catch(err => console.error('error:' + err));