Skip to content
Start here

Update rule

client.MagicNetworkMonitoring.Rules.Edit(ctx, ruleID, params) (*MagicNetworkMonitoringRule, error)
PATCH/accounts/{account_id}/mnm/rules/{rule_id}

Update a network monitoring rule for account.

Security

API Email + API Key

The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

Example:X-Auth-Email: user@example.com

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

Example:X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194
Accepted Permissions (at least one required)
Magic Network Monitoring AdminMagic Network Monitoring Config Write
ParametersExpand Collapse
ruleID string

The id of the rule. Must be unique.

params RuleEditParams
AccountID param.Field[string]Optional

Path param

AutomaticAdvertisement param.Field[bool]

Body param: Toggle on if you would like Cloudflare to automatically advertise the IP Prefixes within the rule via Magic Transit when the rule is triggered. Only available for users of Magic Transit.

Name param.Field[string]

Body param: The name of the rule. Must be unique. Supports characters A-Z, a-z, 0-9, underscore (_), dash (-), period (.), and tilde (~). You can’t have a space in the rule name. Max 256 characters.

Prefixes param.Field[[]string]

Body param

Type param.Field[RuleEditParamsType]

Body param: MNM rule type.

const RuleEditParamsTypeThreshold RuleEditParamsType = "threshold"
const RuleEditParamsTypeZscore RuleEditParamsType = "zscore"
const RuleEditParamsTypeAdvancedDDoS RuleEditParamsType = "advanced_ddos"
BandwidthThreshold param.Field[float64]Optional

Body param: The number of bits per second for the rule. When this value is exceeded for the set duration, an alert notification is sent. Minimum of 1 and no maximum.

minimum1
Duration param.Field[RuleEditParamsDuration]Optional

Body param: The amount of time that the rule threshold must be exceeded to send an alert notification. The final value must be equivalent to one of the following 8 values [“1m”,“5m”,“10m”,“15m”,“20m”,“30m”,“45m”,“60m”].

const RuleEditParamsDuration1m RuleEditParamsDuration = "1m"
const RuleEditParamsDuration5m RuleEditParamsDuration = "5m"
const RuleEditParamsDuration10m RuleEditParamsDuration = "10m"
const RuleEditParamsDuration15m RuleEditParamsDuration = "15m"
const RuleEditParamsDuration20m RuleEditParamsDuration = "20m"
const RuleEditParamsDuration30m RuleEditParamsDuration = "30m"
const RuleEditParamsDuration45m RuleEditParamsDuration = "45m"
const RuleEditParamsDuration60m RuleEditParamsDuration = "60m"
PacketThreshold param.Field[float64]Optional

Body param: The number of packets per second for the rule. When this value is exceeded for the set duration, an alert notification is sent. Minimum of 1 and no maximum.

minimum1
PrefixMatch param.Field[RuleEditParamsPrefixMatch]Optional

Body param: Prefix match type to be applied for a prefix auto advertisement when using an advanced_ddos rule.

const RuleEditParamsPrefixMatchExact RuleEditParamsPrefixMatch = "exact"
const RuleEditParamsPrefixMatchSubnet RuleEditParamsPrefixMatch = "subnet"
const RuleEditParamsPrefixMatchSupernet RuleEditParamsPrefixMatch = "supernet"
ZscoreSensitivity param.Field[RuleEditParamsZscoreSensitivity]Optional

Body param: Level of sensitivity set for zscore rules.

const RuleEditParamsZscoreSensitivityLow RuleEditParamsZscoreSensitivity = "low"
const RuleEditParamsZscoreSensitivityMedium RuleEditParamsZscoreSensitivity = "medium"
const RuleEditParamsZscoreSensitivityHigh RuleEditParamsZscoreSensitivity = "high"
ZscoreTarget param.Field[RuleEditParamsZscoreTarget]Optional

Body param: Target of the zscore rule analysis.

const RuleEditParamsZscoreTargetBits RuleEditParamsZscoreTarget = "bits"
const RuleEditParamsZscoreTargetPackets RuleEditParamsZscoreTarget = "packets"
ReturnsExpand Collapse
type MagicNetworkMonitoringRule struct{…}
ID string

The id of the rule. Must be unique.

AutomaticAdvertisement bool

Toggle on if you would like Cloudflare to automatically advertise the IP Prefixes within the rule via Magic Transit when the rule is triggered. Only available for users of Magic Transit.

Name string

The name of the rule. Must be unique. Supports characters A-Z, a-z, 0-9, underscore (_), dash (-), period (.), and tilde (~). You can’t have a space in the rule name. Max 256 characters.

Prefixes []string
Type MagicNetworkMonitoringRuleType

MNM rule type.

One of the following:
const MagicNetworkMonitoringRuleTypeThreshold MagicNetworkMonitoringRuleType = "threshold"
const MagicNetworkMonitoringRuleTypeZscore MagicNetworkMonitoringRuleType = "zscore"
const MagicNetworkMonitoringRuleTypeAdvancedDDoS MagicNetworkMonitoringRuleType = "advanced_ddos"
BandwidthThreshold float64Optional

The number of bits per second for the rule. When this value is exceeded for the set duration, an alert notification is sent. Minimum of 1 and no maximum.

minimum1
Duration MagicNetworkMonitoringRuleDurationOptional

The amount of time that the rule threshold must be exceeded to send an alert notification. The final value must be equivalent to one of the following 8 values [“1m”,“5m”,“10m”,“15m”,“20m”,“30m”,“45m”,“60m”].

One of the following:
const MagicNetworkMonitoringRuleDuration1m MagicNetworkMonitoringRuleDuration = "1m"
const MagicNetworkMonitoringRuleDuration5m MagicNetworkMonitoringRuleDuration = "5m"
const MagicNetworkMonitoringRuleDuration10m MagicNetworkMonitoringRuleDuration = "10m"
const MagicNetworkMonitoringRuleDuration15m MagicNetworkMonitoringRuleDuration = "15m"
const MagicNetworkMonitoringRuleDuration20m MagicNetworkMonitoringRuleDuration = "20m"
const MagicNetworkMonitoringRuleDuration30m MagicNetworkMonitoringRuleDuration = "30m"
const MagicNetworkMonitoringRuleDuration45m MagicNetworkMonitoringRuleDuration = "45m"
const MagicNetworkMonitoringRuleDuration60m MagicNetworkMonitoringRuleDuration = "60m"
PacketThreshold float64Optional

The number of packets per second for the rule. When this value is exceeded for the set duration, an alert notification is sent. Minimum of 1 and no maximum.

minimum1
PrefixMatch MagicNetworkMonitoringRulePrefixMatchOptional

Prefix match type to be applied for a prefix auto advertisement when using an advanced_ddos rule.

One of the following:
const MagicNetworkMonitoringRulePrefixMatchExact MagicNetworkMonitoringRulePrefixMatch = "exact"
const MagicNetworkMonitoringRulePrefixMatchSubnet MagicNetworkMonitoringRulePrefixMatch = "subnet"
const MagicNetworkMonitoringRulePrefixMatchSupernet MagicNetworkMonitoringRulePrefixMatch = "supernet"
ZscoreSensitivity MagicNetworkMonitoringRuleZscoreSensitivityOptional

Level of sensitivity set for zscore rules.

One of the following:
const MagicNetworkMonitoringRuleZscoreSensitivityLow MagicNetworkMonitoringRuleZscoreSensitivity = "low"
const MagicNetworkMonitoringRuleZscoreSensitivityMedium MagicNetworkMonitoringRuleZscoreSensitivity = "medium"
const MagicNetworkMonitoringRuleZscoreSensitivityHigh MagicNetworkMonitoringRuleZscoreSensitivity = "high"
ZscoreTarget MagicNetworkMonitoringRuleZscoreTargetOptional

Target of the zscore rule analysis.

One of the following:
const MagicNetworkMonitoringRuleZscoreTargetBits MagicNetworkMonitoringRuleZscoreTarget = "bits"
const MagicNetworkMonitoringRuleZscoreTargetPackets MagicNetworkMonitoringRuleZscoreTarget = "packets"

Update rule

package main

import (
  "context"
  "fmt"

  "github.com/cloudflare/cloudflare-go"
  "github.com/cloudflare/cloudflare-go/magic_network_monitoring"
  "github.com/cloudflare/cloudflare-go/option"
)

func main() {
  client := cloudflare.NewClient(
    option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
    option.WithAPIEmail("user@example.com"),
  )
  magicNetworkMonitoringRule, err := client.MagicNetworkMonitoring.Rules.Edit(
    context.TODO(),
    "2890e6fa406311ed9b5a23f70f6fb8cf",
    magic_network_monitoring.RuleEditParams{
      AccountID: cloudflare.F("6f91088a406011ed95aed352566e8d4c"),
      AutomaticAdvertisement: cloudflare.F(true),
      Name: cloudflare.F("my_rule_1"),
      Prefixes: cloudflare.F([]string{"203.0.113.1/32"}),
      Type: cloudflare.F(magic_network_monitoring.RuleEditParamsTypeZscore),
    },
  )
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", magicNetworkMonitoringRule.ID)
}
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "result": {
    "id": "2890e6fa406311ed9b5a23f70f6fb8cf",
    "automatic_advertisement": true,
    "name": "my_rule_1",
    "prefixes": [
      "203.0.113.1/32"
    ],
    "type": "zscore",
    "bandwidth_threshold": 1000,
    "duration": "1m",
    "packet_threshold": 10000,
    "prefix_match": "exact",
    "zscore_sensitivity": "high",
    "zscore_target": "bits"
  },
  "success": true
}
Returns Examples
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "result": {
    "id": "2890e6fa406311ed9b5a23f70f6fb8cf",
    "automatic_advertisement": true,
    "name": "my_rule_1",
    "prefixes": [
      "203.0.113.1/32"
    ],
    "type": "zscore",
    "bandwidth_threshold": 1000,
    "duration": "1m",
    "packet_threshold": 10000,
    "prefix_match": "exact",
    "zscore_sensitivity": "high",
    "zscore_target": "bits"
  },
  "success": true
}