Skip to content
Start here

Update rules

magic_network_monitoring.rules.update(RuleUpdateParams**kwargs) -> MagicNetworkMonitoringRule
PUT/accounts/{account_id}/mnm/rules

Update network monitoring rules 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
account_id: str
duration: Literal["1m", "5m", "10m", 5 more]

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:
"1m"
"5m"
"10m"
"15m"
"20m"
"30m"
"45m"
"60m"
name: str

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.

id: Optional[str]

The id of the rule. Must be unique.

automatic_advertisement: Optional[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.

bandwidth: Optional[float]

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
packet_threshold: Optional[float]

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
prefixes: Optional[SequenceNotStr[str]]
ReturnsExpand Collapse
class MagicNetworkMonitoringRule:
automatic_advertisement: Optional[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: str

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: List[str]
type: Literal["threshold", "zscore", "advanced_ddos"]

MNM rule type.

One of the following:
"threshold"
"zscore"
"advanced_ddos"
id: Optional[str]

The id of the rule. Must be unique.

bandwidth_threshold: Optional[float]

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: Optional[Literal["1m", "5m", "10m", 5 more]]

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:
"1m"
"5m"
"10m"
"15m"
"20m"
"30m"
"45m"
"60m"
packet_threshold: Optional[float]

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
prefix_match: Optional[Literal["exact", "subnet", "supernet"]]

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

One of the following:
"exact"
"subnet"
"supernet"
zscore_sensitivity: Optional[Literal["low", "medium", "high"]]

Level of sensitivity set for zscore rules.

One of the following:
"low"
"medium"
"high"
zscore_target: Optional[Literal["bits", "packets"]]

Target of the zscore rule analysis.

One of the following:
"bits"
"packets"

Update rules

import os
from cloudflare import Cloudflare

client = Cloudflare(
    api_email=os.environ.get("CLOUDFLARE_EMAIL"),  # This is the default and can be omitted
    api_key=os.environ.get("CLOUDFLARE_API_KEY"),  # This is the default and can be omitted
)
magic_network_monitoring_rule = client.magic_network_monitoring.rules.update(
    account_id="6f91088a406011ed95aed352566e8d4c",
    duration="1m",
    name="my_rule_1",
)
print(magic_network_monitoring_rule.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": {
    "automatic_advertisement": true,
    "name": "my_rule_1",
    "prefixes": [
      "203.0.113.1/32"
    ],
    "type": "zscore",
    "id": "2890e6fa406311ed9b5a23f70f6fb8cf",
    "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": {
    "automatic_advertisement": true,
    "name": "my_rule_1",
    "prefixes": [
      "203.0.113.1/32"
    ],
    "type": "zscore",
    "id": "2890e6fa406311ed9b5a23f70f6fb8cf",
    "bandwidth_threshold": 1000,
    "duration": "1m",
    "packet_threshold": 10000,
    "prefix_match": "exact",
    "zscore_sensitivity": "high",
    "zscore_target": "bits"
  },
  "success": true
}