OPNSense
Manage OPNsense Firewall. For more information see OPNsense documentation. OPNsense is an open source, easy-to-use and easy-to-build HardenedBSD based firewall and routing platform.
Network Security · OPNSense
Details
| ID | OPNSense |
|---|---|
| Provider | Deciso B.V. |
| Category | Network Security |
| From Version | 6.0.0 |
| Docker Image | demisto/opnsense:1.0.0.10133006 |
| Supported Modules | Agentix XSIAM |
README
Manage OPNsense Firewall.
For more information see OPNsense documentation.
OPNsense is an open source, easy-to-use and easy-to-build HardenedBSD based firewall and routing platform.
This integration was integrated and tested with version 22.1 of OPNSense
Configure OPNSense in Cortex
| Parameter | Required |
|---|---|
| Server URL (e.g. https://opnsense.mydomain.ltd) | True |
| API Key | True |
| API Secret | True |
| Trust any certificate (not secure) | False |
| Use system proxy settings | False |
Commands
You can execute these commands from the CLI, as part of an automation, or in a playbook.
After you successfully execute a command, a DBot message appears in the War Room with the command details.
opnsense-alias-list
Get aliases list
Base Command
opnsense-alias-list
Input
| Argument Name | Description | Required |
| — | — | — |
Context Output
| Path | Type | Description |
|---|---|---|
| OPNSense.Alias | unknown | Aliases list |
opnsense-alias-add
Create new alias
Base Command
opnsense-alias-add
Input
| Argument Name | Description | Required |
|---|---|---|
| name | Alias name. | Required |
| type | Alias type. Possible values are: host, network, port, url, urltable, geoip, networkgroup, mac, external, dynipv6host. | Required |
| enabled | Alias enabled. Possible values are: 1, 0. Default is 1. | Optional |
| proto | Alias protocol. Possible values are: inet, inet6. | Optional |
| updatefreq | Alias update frequency. | Optional |
| counters | Alias statistics. Possible values are: 0, 1. | Optional |
| description | Alias description. | Optional |
| content | Alias content. | Optional |
| auto_commit | Apply automaticly aliases changes. Possible values are: False, True. Default is False. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| OPNSense.Alias | unknown | Alias UUID created |
opnsense-alias-del
Delete alias with uuid
Base Command
opnsense-alias-del
Input
| Argument Name | Description | Required |
|---|---|---|
| uuid | Alias UUID. | Required |
| auto_commit | Apply automaticly aliases changes. Possible values are: False, True. Default is False. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| OPNSense.Alias | unknown | Alias UUID deleted |
opnsense-alias-mod
Modify an existing alias
Base Command
opnsense-alias-mod
Input
| Argument Name | Description | Required |
|---|---|---|
| uuid | Alias UUID. | Required |
| content | Alias content seperated by comma (NB. will replace actual content!). | Required |
| name | Alias name. | Optional |
| type | Alias type. Possible values are: host, network, port, url, urltable, geoip, networkgroup, mac, external, dynipv6host. | Optional |
| proto | Alias protocol. Possible values are: inet, inet6. | Optional |
| enabled | Alias enabled. Possible values are: 0, 1. | Optional |
| updatefreq | Alias update frequency. | Optional |
| counters | Alias statistics. Possible values are: 0, 1. | Optional |
| description | Alias description. | Optional |
| auto_commit | Apply automaticly aliases changes. Possible values are: False, True. Default is False. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| OPNSense.Alias | unknown | Alias UUID modified |
opnsense-alias-mod-additem
Add item into existing alias
Base Command
opnsense-alias-mod-additem
Input
| Argument Name | Description | Required |
|---|---|---|
| name | Alias name. | Required |
| entry | Entry to add. | Optional |
| auto_commit | Apply automaticly aliases changes. Possible values are: False, True. Default is False. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| OPNSense.Alias | unknown | Alias UUID modified |
opnsense-alias-mod-delitem
Del item into existing alias
Base Command
opnsense-alias-mod-delitem
Input
| Argument Name | Description | Required |
|---|---|---|
| name | Alias name. | Required |
| entry | Entry to remove. | Optional |
| auto_commit | Apply automaticly aliases changes. Possible values are: False, True. Default is False. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| OPNSense.Alias | unknown | Alias UUID modified |
opnsense-alias-get
Get alias details
Base Command
opnsense-alias-get
Input
| Argument Name | Description | Required |
|---|---|---|
| uuid | Alias UUID. | Optional |
| name | Alias name. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| OPNSense.Alias | Unknown | Alias details |
| OPNSense.Alias.name | Unknown | Alias name |
| OPNSense.Alias.content | Unknown | Alias content |
| OPNSense.Alias.description | Unknown | Alias description |
| OPNSense.Alias.enabled | Unknown | Alias enabled |
opnsense-alias-get-uuid
Get alias UUID
Base Command
opnsense-alias-get-uuid
Input
| Argument Name | Description | Required |
|---|---|---|
| name | Alias name. | Required |
Context Output
| Path | Type | Description |
|---|---|---|
| OPNSense.Alias | Unknown | Alias UUID |
opnsense-interfaces-list
Get interfaces list
Base Command
opnsense-interfaces-list
Input
| Argument Name | Description | Required |
| — | — | — |
Context Output
| Path | Type | Description |
|---|---|---|
| OPNSense.Interfaces | Unknown | Interfaces list |
opnsense-category-list
Get categories list
Base Command
opnsense-category-list
Input
| Argument Name | Description | Required |
| — | — | — |
Context Output
| Path | Type | Description |
|---|---|---|
| OPNSense.Category | Unknown | Categories list |
opnsense-category-add
Create new category
Base Command
opnsense-category-add
Input
| Argument Name | Description | Required |
|---|---|---|
| name | Category name. | Required |
| auto | Automatically added, will be removed when unused. Possible values are: 0, 1. | Optional |
| color | Category color (format : #YVWXYZ). | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| OPNSense.Category | Unknown | Category UUID |
opnsense-category-del
Delete category with uuid
Base Command
opnsense-category-del
Input
| Argument Name | Description | Required |
|---|---|---|
| uuid | Category UUID. | Required |
Context Output
| Path | Type | Description |
|---|---|---|
| OPNSense.Category | Unknown | Category UUID |
opnsense-category-get
Get category details
Base Command
opnsense-category-get
Input
| Argument Name | Description | Required |
|---|---|---|
| uuid | Category UUID. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| OPNSense.Category | Unknown | Category details |
opnsense-category-mod
Modify an axisting category
Base Command
opnsense-category-mod
Input
| Argument Name | Description | Required |
|---|---|---|
| uuid | Category UUID. | Required |
| name | Category name. | Optional |
| color | Category color (format : #YVWXYZ). | Optional |
| auto | Automatically added, will be removed when unused. Possible values are: 0, 1. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| cef2c7d7-68d8-41aa-b6b8-1cac38554d58 | Unknown | Category UUID |
opnsense-rule-list
Get rules list
Base Command
opnsense-rule-list
Input
| Argument Name | Description | Required |
| — | — | — |
Context Output
| Path | Type | Description |
|---|---|---|
| OPNSense.Rule | Unknown | Rules list |
opnsense-rule-get
Get rule details
Base Command
opnsense-rule-get
Input
| Argument Name | Description | Required |
|---|---|---|
| uuid | Rule UUID. | Required |
Context Output
| Path | Type | Description |
|---|---|---|
| OPNSense.Rule | Unknown | Rule details |
| OPNSense.Rule.description | Unknown | Rule description |
| OPNSense.Rule.enabled | Unknown | Rule enabled |
| OPNSense.Rule.source_net | Unknown | Source NET’s rule |
| OPNSense.Rule.destination_net | Unknown | Destination NET’s rule |
| OPNSense.Rule.interface | Unknown | Interface’s rule |
opnsense-alias-apply
Apply configuration
Base Command
opnsense-alias-apply
Input
| Argument Name | Description | Required |
| — | — | — |
Context Output
There is no context output for this command.
opnsense-device-reboot
Reboot the device
Base Command
opnsense-device-reboot
Input
| Argument Name | Description | Required |
| — | — | — |
Context Output
| Path | Type | Description |
|---|---|---|
| OPNSense.Device | Unknown | Reboot status |
opnsense-firmware-info
Get firmware info
Base Command
opnsense-firmware-info
Input
| Argument Name | Description | Required |
| — | — | — |
Context Output
| Path | Type | Description |
|---|---|---|
| OPNSense.Firmware | Unknown | Firmware info |
opnsense-firmware-status
Get firmware status
Base Command
opnsense-firmware-status
Input
| Argument Name | Description | Required |
| — | — | — |
Context Output
| Path | Type | Description |
|---|---|---|
| OPNSense.Firmware | Unknown | Firmware status |
opnsense-firmware-upgradestatus
Get firmware upgrade status
Base Command
opnsense-firmware-upgradestatus
Input
| Argument Name | Description | Required |
| — | — | — |
Context Output
| Path | Type | Description |
|---|---|---|
| OPNSense.Firmware | Unknown | Firmware upgrade status |
opnsense-firmware-update
Do firmware update
Base Command
opnsense-firmware-update
Input
| Argument Name | Description | Required |
| — | — | — |
Context Output
| Path | Type | Description |
|---|---|---|
| OPNSense.Firmware | Unknown | Firmware update |
opnsense-firmware-upgrade
Do firmware upgrade
Base Command
opnsense-firmware-upgrade
Input
| Argument Name | Description | Required |
| — | — | — |
Context Output
| Path | Type | Description |
|---|---|---|
| OPNSense.Firmware | Unknown | Firmware upgrade |
opnsense-rule-del
Delete an existing rule
Base Command
opnsense-rule-del
Input
| Argument Name | Description | Required |
|---|---|---|
| uuid | Rule UUID. | Required |
| auto_commit | Apply automaticly aliases changes. Possible values are: None, True. Default is None. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| OPNSense.Rule | Unknown | Rule UUID |
opnsense-rule-add
Create a new rule
Base Command
opnsense-rule-add
Input
| Argument Name | Description | Required |
|---|---|---|
| action | Rule action. Possible values are: pass, block, reject. Default is pass. | Optional |
| enabled | Rule enabled. Possible values are: 1, 0. Default is 1. | Optional |
| quick | Rule quick. Possible values are: 1, 0. Default is 1. | Optional |
| interface | Rule interface. | Optional |
| direction | Rule direction. Possible values are: in, out. Default is in. | Optional |
| ipprotocol | Rule IP Protocol. Possible values are: inet, inet6. Default is inet. | Optional |
| protocol | Rule protocol. Possible values are: any, ICMP, IGMP, GGP, IPENCAP, ST2, TCP, CBT, EGP, IGP, BBN-RCC, NVP, PUP, ARGUS, EMCON, XNET, CHAOS, UDP, MUX, DCN, HMP, PRM, XNS-IDP, TRUNK-1, TRUNK-2, LEAF-1, LEAF-2, RDP, ISO-TP4, NETBLT, MFE-NSP, MERIT-INP, DCCP, 3PC, IDPR, XTP, DDP, IDPR-CMTP, TP++, IL, IPV6, SDRP, IDRP, RSVP, GRE, DSR, BNA, ESP, AH, I-NLSP, SWIPE, NARP, MOBILE, TLSP, SKIP, IPV6-ICMP, CFTP, SAT-EXPAK, KRYPTOLAN, RVD, IPPC, SAT-MON, VISA, IPCV, CPNX, CPHB, WSN, PVP, BR-SAT-MON, SUN-ND, WB-MON, WB-EXPAK, ISO-IP, VMTP, SECURE-VMTP, VINES, TTP, NSFNET-IGP, DGP, TCF, EIGRP, OSPF, SPRITE-RPC, LARP, MTP, AX.25, IPIP, MICP, SCC-SP, ETHERIP, ENCAP, GMTP, IFMP, PNNI, PIM, ARIS, SCPS, QNX, A/N, IPCOMP, SNP, COMPAQ-PEER, IPX-IN-IP, CARP, PGM, L2TP, DDX, IATP, STP, SRP, UTI, SMP, SM, PTP, ISIS, CRTP, CRUDP, SPS, PIPE, SCTP, FC, RSVP-E2E-IGNORE, UDPLITE, MPLS-IN-IP, MANET, HIP, SHIM6, WESP, ROHC, PFSYNC, DIVERT. Default is any. | Optional |
| source_net | Source Net. Default is any. | Optional |
| source_not | Source NOT. Possible values are: 0, 1. Default is 0. | Optional |
| source_port | Source port. | Optional |
| destination_net | Destination Net. Default is any. | Optional |
| destination_not | Destination NOT. Possible values are: 0, 1. Default is 0. | Optional |
| destination_port | Destination port. | Optional |
| log | Enable logging. Possible values are: 0, 1. Default is 0. | Optional |
| sequence | Provide a valid sequence for sorting (1 - 99999). Default is 1. | Optional |
| description | Rule description. | Optional |
| auto_commit | Apply automaticly aliases changes. Possible values are: None, True. Default is None. | Required |
Context Output
| Path | Type | Description |
|---|---|---|
| OPNSense.Rule | Unknown | Rule UUID |
opnsense-rule-mod
Modify an existing rule
Base Command
opnsense-rule-mod
Input
| Argument Name | Description | Required |
|---|---|---|
| uuid | Rule UUID. | Required |
| action | Rule action. Possible values are: pass, block, reject. Default is pass. | Optional |
| enabled | Rule enabled. Possible values are: 1, 0. Default is 1. | Optional |
| quick | Rule quick. Possible values are: 1, 0. Default is 1. | Optional |
| interface | Rule interface. | Optional |
| direction | Rule description. Possible values are: in, out. Default is in. | Optional |
| ipprotocol | Rule IP protocol. Possible values are: inet, inet6. Default is inet. | Optional |
| protocol | Rule protocol. Possible values are: any, ICMP, IGMP, GGP, IPENCAP, ST2, TCP, CBT, EGP, IGP, BBN-RCC, NVP, PUP, ARGUS, EMCON, XNET, CHAOS, UDP, MUX, DCN, HMP, PRM, XNS-IDP, TRUNK-1, TRUNK-2, LEAF-1, LEAF-2, RDP, ISO-TP4, NETBLT, MFE-NSP, MERIT-INP, DCCP, 3PC, IDPR, XTP, DDP, IDPR-CMTP, TP++, IL, IPV6, SDRP, IDRP, RSVP, GRE, DSR, BNA, ESP, AH, I-NLSP, SWIPE, NARP, MOBILE, TLSP, SKIP, IPV6-ICMP, CFTP, SAT-EXPAK, KRYPTOLAN, RVD, IPPC, SAT-MON, VISA, IPCV, CPNX, CPHB, WSN, PVP, BR-SAT-MON, SUN-ND, WB-MON, WB-EXPAK, ISO-IP, VMTP, SECURE-VMTP, VINES, TTP, NSFNET-IGP, DGP, TCF, EIGRP, OSPF, SPRITE-RPC, LARP, MTP, AX.25, IPIP, MICP, SCC-SP, ETHERIP, ENCAP, GMTP, IFMP, PNNI, PIM, ARIS, SCPS, QNX, A/N, IPCOMP, SNP, COMPAQ-PEER, IPX-IN-IP, CARP, PGM, L2TP, DDX, IATP, STP, SRP, UTI, SMP, SM, PTP, ISIS, CRTP, CRUDP, SPS, PIPE, SCTP, FC, RSVP-E2E-IGNORE, UDPLITE, MPLS-IN-IP, MANET, HIP, SHIM6, WESP, ROHC, PFSYNC, DIVERT. | Optional |
| source_net | Source Net. | Optional |
| source_not | Source NOT. Possible values are: 0, 1. Default is 0. | Optional |
| source_port | Source port. | Optional |
| destination_net | Destination Net. | Optional |
| destination_not | Destination NOT. | Optional |
| destination_port | Destination port. | Optional |
| log | Enable log. Possible values are: 0, 1. Default is 0. | Optional |
| description | Rule description. | Optional |
| auto_commit | Apply automaticly aliases changes. Possible values are: None, True. Default is None. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| OPNSense.Rule | Unknown | Rule UUID |
opnsense-rule-apply
Apply rules current configuration
Base Command
opnsense-rule-apply
Input
| Argument Name | Description | Required |
|---|---|---|
| rollback_revision | Rollback revision. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| OPNSense.Rule | Unknown | Action status |
opnsense-rule-savepoint
Save rules current configuration
Base Command
opnsense-rule-savepoint
Input
| Argument Name | Description | Required |
| — | — | — |
Context Output
| Path | Type | Description |
|---|---|---|
| OPNSense.Rule | Unknown | Action status |
opnsense-logs-search
Search into firewall logs
Base Command
opnsense-logs-search
Input
| Argument Name | Description | Required |
|---|---|---|
| limit | Log search limit. Default is 1000. | Optional |
| ip | Search IP in src or dst. | Optional |
| interface | Interface search filter. | Optional |
Context Output
| Path | Type | Description |
|—————————–| — | — |
| OPNSense.Logs | Unknown | OPNSense logs |
| OPNSense.Logs.interface | Unknown | interface in logs |
| OPNSense.Logs.src | Unknown | SRC in logs |
| OPNSense.Logs.srcport | Unknown | SRCPORT in logs |
| OPNSense.Logs.dst | Unknown | DST in logs |
| OPNSense.Logs.dstport | Unknown | DSTPORT in logs |
| OPNSense.Logs.action | Unknown | Action in logs |
| OPNSense.Logs.timestamp | Unknown | timestamp in logs |
| OPNSense.Logs.label | Unknown | label in logs |
| OPNSense.Logs.protoname | Unknown | protoname in logs |
opnsense-states-search
Query states
Base Command
opnsense-states-search
Input
| Argument Name | Description | Required |
|---|---|---|
| ip | Search IP in src or dst. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| OPNSense.States | Unknown | OPNSense States |
| OPNSense.States.label | Unknown | label in states |
| OPNSense.States.descr | Unknown | states description |
| OPNSense.States.nat_addr | Unknown | nat address in states |
| OPNSense.States.nat_port | Unknown | nat port in states |
| OPNSense.States.iface | Unknown | interface in states |
| OPNSense.States.ipproto | Unknown | IP Protocol in states |
| OPNSense.States.proto | Unknown | Protocol in states |
opnsense-state-del
Delete state with ID
Base Command
opnsense-state-del
Input
| Argument Name | Description | Required |
|---|---|---|
| state_id | State ID. | Optional |
Context Output
There is no context output for this command.
opnsense-rule-revert
Revert config to given savepoint
Base Command
opnsense-rule-revert
Input
| Argument Name | Description | Required |
|---|---|---|
| rollback_revision | Rollback revision. | Optional |
Context Output
There is no context output for this command.
Configuration parameters
url— Server URL (e.g. https://opnsense.mydomain.ltd) (required)apikey— API Key (required)apisecret— API Secret (required)insecure— Trust any certificate (not secure)proxy— Use system proxy settings
Commands (32)
-
opnsense-alias-addCreate new alias.
-
opnsense-alias-applyApply configuration.
-
opnsense-alias-delDelete alias with uuid.
-
opnsense-alias-getGet alias details.
-
opnsense-alias-get-uuidGet alias UUID.
-
opnsense-alias-listGet aliases list.
-
opnsense-alias-modModify an existing alias.
-
opnsense-alias-mod-additemAdd item into existing alias.
-
opnsense-alias-mod-delitemDel item into existing alias.
-
opnsense-category-addCreate new category.
-
opnsense-category-delDelete category with uuid.
-
opnsense-category-getGet category details.
-
opnsense-category-listGet categories list.
-
opnsense-category-modModify an axisting category.
-
opnsense-device-rebootReboot the device.
-
opnsense-firmware-infoGet firmware info.
-
opnsense-firmware-statusGet firmware status.
-
opnsense-firmware-updateDo firmware update.
-
opnsense-firmware-upgradeDo firmware upgrade.
-
opnsense-firmware-upgradestatusGet firmware upgrade status.
-
opnsense-interfaces-listGet interfaces list.
-
opnsense-logs-searchSearch into firewall logs.
-
opnsense-rule-addCreate a new rule.
-
opnsense-rule-applyApply rules current configuration.
-
opnsense-rule-delDelete an existing rule.
-
opnsense-rule-getGet rule details.
-
opnsense-rule-listGet rules list.
-
opnsense-rule-modModify an existing rule.
-
opnsense-rule-revertRevert config to given savepoint.
-
opnsense-rule-savepointSave rules current configuration.
-
opnsense-state-delDelete state with ID.
-
opnsense-states-searchQuery states.
"""OPNSense Integration for Cortex XSOAR - Unit Tests file""" import ast import json def util_load_json(path): with open(path, encoding="utf-8") as f: return json.loads(f.read()) def util_load_mock(path): with open(path) as f: data = f.read() return ast.literal_eval(data) MOCK_PARAMETERS = { "base_url": "https://opnsense.mockserver.com/api", "auth": ( "NTVjNzhjNGE0MzkzMzUzMzJjNjY4ZDA2NjQzYTkwY2Q3ZDIyODExMzAzOWEzZmNmODNhMTU3ZmFkMDBmNGY5Mg", "NzYyMDgzYThlYjU1OTZlMGY5ZTdmY2MwMDk1NDI2MTMyMGMxZDZlNzhlOWZjMzIyNzQ0NmJjYmEzZWQ0MDUyYQ", ), "verify_cert": False, "proxy": False, "timeout": 60, } def test_opnsense_alias_apply(requests_mock): from OPNSense import Client, alias_apply_command mock_response = {"status": "ok"} requests_mock.post("https://opnsense.mockserver.com/api/firewall/alias/reconfigure/", json=mock_response) client = Client(MOCK_PARAMETERS) response = alias_apply_command(client) assert response.outputs_prefix == "OPNSense.Alias" assert response.outputs == '{"status": "ok"}' def test_opnsense_alias_list(requests_mock): from OPNSense import Client, alias_list_command mock_response = ["alias1", "alias2", "alias3"] requests_mock.get("https://opnsense.mockserver.com/api/firewall/alias_util/aliases/", json=mock_response) client = Client(MOCK_PARAMETERS) response = alias_list_command(client) assert response.outputs_prefix == "OPNSense.Alias" assert response.outputs == '["alias1", "alias2", "alias3"]' def test_opnsense_alias_add(requests_mock): from OPNSense import Client, alias_add_command mock_args = {"name": "NewAlias", "type": "host", "content": "1.2.3.4", "description": "MyNewAlias"} mock_response = {"result": "saved", "uuid": "8abfa542-4031-4e63-9ccd-34ffd31886d4"} requests_mock.post("https://opnsense.mockserver.com/api/firewall/alias/addItem/", json=mock_response) client = Client(MOCK_PARAMETERS) response = alias_add_command(client, mock_args) assert response[0].outputs_prefix == "OPNSense.Alias" assert response[0].outputs == {"result": "saved", "uuid": "8abfa542-4031-4e63-9ccd-34ffd31886d4"} def test_opnsense_alias_mod(requests_mock): from OPNSense import Client, alias_mod_command mock_args = { "uuid": "8abfa542-4031-4e63-9ccd-34ffd31886d4", "description": "MyRenamedAlias", "content": "1.2.3.4", "name": "RenamedAlias", } mock_response = util_load_json("test_data/opnsense_alias_mod.json") requests_mock.get( "https://opnsense.mockserver.com/api/firewall/alias/getItem/8abfa542-4031-4e63-9ccd-34ffd31886d4/", json=mock_response ) mock_response2 = {"result": "saved"} requests_mock.post( "https://opnsense.mockserver.com/api/firewall/alias/setItem/8abfa542-4031-4e63-9ccd-34ffd31886d4/", json=mock_response2 ) client = Client(MOCK_PARAMETERS) response = alias_mod_command(client, mock_args) assert response[0].outputs_prefix == "OPNSense.Alias" assert response[0].outputs == {"result": "saved"} def test_opnsense_alias_mod_additem(requests_mock): from OPNSense import Client, alias_mod_additem_command mock_args = {"name": "NewAlias", "entry": "1.2.3.4"} mock_response = {"status": "done"} requests_mock.post("https://opnsense.mockserver.com/api/firewall/alias_util/add/NewAlias/", json=mock_response) client = Client(MOCK_PARAMETERS) response = alias_mod_additem_command(client, mock_args) assert response[0].outputs_prefix == "OPNSense.Alias" assert response[0].outputs == {"status": "done"} def test_opnsense_alias_mod_delitem(requests_mock): from OPNSense import Client, alias_mod_delitem_command mock_args = {"name": "NewAlias", "entry": "1.2.3.4"} mock_response = {"status": "done"} requests_mock.post("https://opnsense.mockserver.com/api/firewall/alias_util/delete/NewAlias/", json=mock_response) client = Client(MOCK_PARAMETERS) response = alias_mod_delitem_command(client, mock_args) assert response[0].outputs_prefix == "OPNSense.Alias" assert response[0].outputs == {"status": "done"} def test_opnsense_alias_del(requests_mock): from OPNSense import Client, alias_del_command mock_args = {"uuid": "8abfa542-4031-4e63-9ccd-34ffd31886d4"} mock_response = {"result": "deleted"} requests_mock.post( "https://opnsense.mockserver.com/api/firewall/alias/delItem/8abfa542-4031-4e63-9ccd-34ffd31886d4/", json=mock_response ) client = Client(MOCK_PARAMETERS) response = alias_del_command(client, mock_args) assert response[0].outputs_prefix == "OPNSense.Alias" assert response[0].outputs == {"result": "deleted"} def test_opnsense_alias_get(requests_mock): from OPNSense import Client, alias_get_command mock_args = {"uuid": "8abfa542-4031-4e63-9ccd-34ffd31886d4"} mock_response = util_load_json("test_data/opnsense_alias_get.json") requests_mock.get( "https://opnsense.mockserver.com/api/firewall/alias/getItem/8abfa542-4031-4e63-9ccd-34ffd31886d4/", json=mock_response ) client = Client(MOCK_PARAMETERS) response = alias_get_command(client, mock_args) assert response[0].outputs_prefix == "OPNSense.Alias" assert response[0].outputs == { "enabled": "1", "name": "NewAlias", "type": "host", "proto": "", "interface": "", "counters": "", "updatefreq": "", "content": "1.2.3.4", "description": "MyNewAlias", } def test_opnsense_alias_getuuid(requests_mock): from OPNSense import Client, alias_getuuid_command mock_args = {"name": "NewAlias"} mock_response = {"uuid": "8abfa542-4031-4e63-9ccd-34ffd31886d4"} requests_mock.get("https://opnsense.mockserver.com/api/firewall/alias/getAliasUUID/NewAlias/", json=mock_response) client = Client(MOCK_PARAMETERS) response = alias_getuuid_command(client, mock_args) assert response.outputs_prefix == "OPNSense.Alias" assert response.outputs == '"8abfa542-4031-4e63-9ccd-34ffd31886d4"' def test_opnsense_interfaces_list(requests_mock): from OPNSense import Client, interfaces_list_command mock_response = {"int1": "name1", "int2": "name2", "int3": "name3"} requests_mock.get("https://opnsense.mockserver.com/api/diagnostics/interface/getInterfaceNames/", json=mock_response) client = Client(MOCK_PARAMETERS) response = interfaces_list_command(client) assert response[0].outputs_prefix == "OPNSense.Interfaces" assert response[0].outputs == {"int1": "name1", "int2": "name2", "int3": "name3"} def test_opnsense_logs_search(requests_mock): from OPNSense import Client, logs_search_command mock_args = {"limit": 5} mock_response = util_load_mock("test_data/opnsense_logs_search.mock") requests_mock.get("https://opnsense.mockserver.com/api/diagnostics/firewall/log/?limit=5", json=mock_response) client = Client(MOCK_PARAMETERS) response = logs_search_command(client, mock_args) assert response[0].outputs_prefix == "OPNSense.Logs" assert response[0].outputs == util_load_mock("test_data/opnsense_logs_search.res.mock") def test_opnsense_states_search(requests_mock): from OPNSense import Client, states_search_command mock_args = {"limit": 5} mock_response = util_load_mock("test_data/opnsense_states_search.mock") requests_mock.post("https://opnsense.mockserver.com/api/diagnostics/firewall/queryStates/", json=mock_response) client = Client(MOCK_PARAMETERS) response = states_search_command(client, mock_args) assert response[0].outputs_prefix == "OPNSense.States" assert response[0].outputs == util_load_mock("test_data/opnsense_states_search.res.mock") def test_opnsense_states_del(requests_mock): from OPNSense import Client, state_del_command mock_args = {"state_id": "0006466200000003/ef725303"} mock_response = {"result": "killed 1 states\n\n\n"} requests_mock.post( "https://opnsense.mockserver.com/api/diagnostics/firewall/delState/0006466200000003/ef725303", json=mock_response ) client = Client(MOCK_PARAMETERS) response = state_del_command(client, mock_args) assert response == {"result": "killed 1 states\n\n\n"} def test_opnsense_category_list(requests_mock): from OPNSense import Client, category_list_command mock_response = { "rows": [ {"uuid": "cef2c7d7-68d8-41aa-b6b8-1cac38554d58", "name": "Categ1", "auto": "1", "color": ""}, {"uuid": "5c30d496-72e6-40ee-aef3-9f27300733f6", "name": "Categ2", "auto": "1", "color": ""}, {"uuid": "a5c385cb-2328-486e-b200-482efebf8248", "name": "Categ3", "auto": "1", "color": ""}, ] } requests_mock.get("https://opnsense.mockserver.com/api/firewall/category/searchItem/", json=mock_response) client = Client(MOCK_PARAMETERS) response = category_list_command(client) assert response[0].outputs_prefix == "OPNSense.Category" assert response[0].outputs == [ {"uuid": "cef2c7d7-68d8-41aa-b6b8-1cac38554d58", "name": "Categ1", "auto": "1", "color": ""}, {"uuid": "5c30d496-72e6-40ee-aef3-9f27300733f6", "name": "Categ2", "auto": "1", "color": ""}, {"uuid": "a5c385cb-2328-486e-b200-482efebf8248", "name": "Categ3", "auto": "1", "color": ""}, ] def test_opnsense_category_add(requests_mock): from OPNSense import Client, category_add_command mock_args = {"name": "NewCategory", "auto": "0", "color": ""} mock_response = {"result": "saved", "uuid": "e291bafc-0696-457b-aa97-6377af4a818a"} requests_mock.post("https://opnsense.mockserver.com/api/firewall/category/addItem/", json=mock_response) client = Client(MOCK_PARAMETERS) response = category_add_command(client, mock_args) assert response[0].outputs_prefix == "OPNSense.Category" assert response[0].outputs == {"result": "saved", "uuid": "e291bafc-0696-457b-aa97-6377af4a818a"} def test_opnsense_category_del(requests_mock): from OPNSense import Client, category_del_command mock_args = {"uuid": "e291bafc-0696-457b-aa97-6377af4a818a"} mock_response = {"result": "deleted"} requests_mock.post( "https://opnsense.mockserver.com/api/firewall/category/delItem/e291bafc-0696-457b-aa97-6377af4a818a/", json=mock_response ) client = Client(MOCK_PARAMETERS) response = category_del_command(client, mock_args) assert response[0].outputs_prefix == "OPNSense.Category" assert response[0].outputs == {"result": "deleted"} def test_opnsense_category_get(requests_mock): from OPNSense import Client, category_get_command mock_args = {"uuid": "e291bafc-0696-457b-aa97-6377af4a818a"} mock_response = {"category": {"name": "NewCategory", "auto": "0", "color": ""}} requests_mock.get( "https://opnsense.mockserver.com/api/firewall/category/getItem/e291bafc-0696-457b-aa97-6377af4a818a/", json=mock_response ) client = Client(MOCK_PARAMETERS) response = category_get_command(client, mock_args) assert response[0].outputs_prefix == "OPNSense.Category" assert response[0].outputs == {"name": "NewCategory", "auto": "0", "color": ""} def test_opnsense_category_mod(requests_mock): from OPNSense import Client, category_mod_command mock_args = {"uuid": "8abfa542-4031-4e63-9ccd-34ffd31886d4", "name": "RenamedCategory", "auto": "0", "color": ""} mock_response = {"category": {"name": "NewCategory", "auto": "0", "color": ""}} requests_mock.get( "https://opnsense.mockserver.com/api/firewall/category/getItem/8abfa542-4031-4e63-9ccd-34ffd31886d4/", json=mock_response ) mock_response2 = {"result": "saved"} requests_mock.post( "https://opnsense.mockserver.com/api/firewall/category/setItem/8abfa542-4031-4e63-9ccd-34ffd31886d4/", json=mock_response2 ) client = Client(MOCK_PARAMETERS) response = category_mod_command(client, mock_args) assert response[0].outputs_prefix == "OPNSense.Category" assert response[0].outputs == {"result": "saved"} def test_opnsense_fw_rule_list(requests_mock): from OPNSense import Client, fw_rule_list_command mock_response = { "rows": [ {"uuid": "443ebf6b-e4d5-4317-84ad-dca961b4821d", "enabled": "1", "sequence": "1", "description": "Rule1"}, {"uuid": "443ebf6b-e4d5-4317-84ad-dca961b4821d", "enabled": "1", "sequence": "1", "description": "Rule2"}, ], "rowCount": 1, "total": 1, "current": 1, } requests_mock.get("https://opnsense.mockserver.com/api/firewall/filter/searchRule/", json=mock_response) client = Client(MOCK_PARAMETERS) response = fw_rule_list_command(client) assert response[0].outputs_prefix == "OPNSense.Rule" assert response[0].outputs == [ {"uuid": "443ebf6b-e4d5-4317-84ad-dca961b4821d", "enabled": "1", "sequence": "1", "description": "Rule1"}, {"uuid": "443ebf6b-e4d5-4317-84ad-dca961b4821d", "enabled": "1", "sequence": "1", "description": "Rule2"}, ] def test_opnsense_fw_rule_get(requests_mock): from OPNSense import Client, fw_rule_get_command mock_args = {"uuid": "e37b5bb2-b96f-455a-a2cb-5542103e5ac2"} mock_response = util_load_json("test_data/opnsense_rule_get.json") requests_mock.get( "https://opnsense.mockserver.com/api/firewall/filter/getRule/e37b5bb2-b96f-455a-a2cb-5542103e5ac2/", json=mock_response ) client = Client(MOCK_PARAMETERS) response = fw_rule_get_command(client, mock_args) assert response[0].outputs_prefix == "OPNSense.Rule" assert response[0].outputs == util_load_mock("test_data/opnsense_fw_rule_get.res.mock") def test_opnsense_fw_rule_del(requests_mock): from OPNSense import Client, fw_rule_del_command mock_args = {"uuid": "e37b5bb2-b96f-455a-a2cb-5542103e5ac2"} mock_response = {"result": "deleted"} requests_mock.post( "https://opnsense.mockserver.com/api/firewall/filter/delRule/e37b5bb2-b96f-455a-a2cb-5542103e5ac2/", json=mock_response ) client = Client(MOCK_PARAMETERS) response = fw_rule_del_command(client, mock_args) assert response[0].outputs_prefix == "OPNSense.Rule" assert response[0].outputs == {"result": "deleted"} def test_opnsense_fw_rule_add(requests_mock): from OPNSense import Client, fw_rule_add_command mock_args = { "description": "MyNew Rule", "source_net": "192.168.10.0/24", "dest_net": "192.168.20.0/24", "protocol": "TCP", "interface": "opt1", } mock_response = {"result": "saved", "uuid": "e37b5bb2-b96f-455a-a2cb-5542103e5ac2"} requests_mock.post("https://opnsense.mockserver.com/api/firewall/filter/addRule/", json=mock_response) client = Client(MOCK_PARAMETERS) response = fw_rule_add_command(client, mock_args) assert response[0].outputs_prefix == "OPNSense.Rule" assert response[0].outputs == {"result": "saved", "uuid": "e37b5bb2-b96f-455a-a2cb-5542103e5ac2"} def test_opnsense_fw_rule_mod(requests_mock): from OPNSense import Client, fw_rule_mod_command mock_args = {"uuid": "e37b5bb2-b96f-455a-a2cb-5542103e5ac2", "description": "My renamed Rule"} mock_response = util_load_json("test_data/opnsense_rule_mod.json") requests_mock.get( "https://opnsense.mockserver.com/api/firewall/filter/getRule/e37b5bb2-b96f-455a-a2cb-5542103e5ac2/", json=mock_response ) mock_response2 = {"result": "saved"} requests_mock.post( "https://opnsense.mockserver.com/api/firewall/filter/setRule/e37b5bb2-b96f-455a-a2cb-5542103e5ac2/", json=mock_response2 ) client = Client(MOCK_PARAMETERS) response = fw_rule_mod_command(client, mock_args) assert response[0].outputs_prefix == "OPNSense.Rule" assert response[0].outputs == {"result": "saved"} def test_opnsense_fw_rule_apply(requests_mock): from OPNSense import Client, fw_rule_apply_command mock_args = {"rollback_revision": None} mock_response = {"status": "ok"} requests_mock.post("https://opnsense.mockserver.com/api/firewall/filter/apply/", json=mock_response) client = Client(MOCK_PARAMETERS) response = fw_rule_apply_command(client, mock_args) assert response[0].outputs_prefix == "OPNSense.Rule" assert response[0].outputs == {"status": "ok"} def test_opnsense_fw_rule_savepoint(requests_mock): from OPNSense import Client, fw_rule_savepoint_command mock_response = {"status": "ok", "retention": 100, "revision": "1648740593.4431"} requests_mock.post("https://opnsense.mockserver.com/api/firewall/filter/savepoint/", json=mock_response) client = Client(MOCK_PARAMETERS) response = fw_rule_savepoint_command(client) assert response[0].outputs_prefix == "OPNSense.Rule" assert response[0].outputs == {"status": "ok", "retention": 100, "revision": "1648740593.4431"} def test_opnsense_fw_rule_revert(requests_mock): from OPNSense import Client, fw_rule_revert_command mock_args = {"rollback_revision": "1648740593.4431"} mock_response = {"status": "ok"} requests_mock.post("https://opnsense.mockserver.com/api/firewall/filter/revert/1648740593.4431/", json=mock_response) client = Client(MOCK_PARAMETERS) response = fw_rule_revert_command(client, mock_args) assert response[0].outputs_prefix == "OPNSense.Rule" assert response[0].outputs == {"status": "ok"} def test_opnsense_device_reboot(requests_mock): from OPNSense import Client, device_reboot_command mock_response = {"status": "ok"} requests_mock.get("https://opnsense.mockserver.com/api/core/system/reboot/", json=mock_response) client = Client(MOCK_PARAMETERS) response = device_reboot_command(client) assert response[0].outputs_prefix == "OPNSense.Device" assert response[0].outputs == {"status": "ok"} def test_opnsense_firmware_info(requests_mock): from OPNSense import Client, firmware_info_command mock_response = util_load_json("test_data/opnsense_firmware_info.json") requests_mock.get("https://opnsense.mockserver.com/api/core/firmware/info/", json=mock_response) client = Client(MOCK_PARAMETERS) response = firmware_info_command(client) assert response[0].outputs_prefix == "OPNSense.Firmware" assert response[0].outputs == util_load_json("test_data/opnsense_firmware_info.json") def test_opnsense_firmware_status(requests_mock): from OPNSense import Client, firmware_status_command mock_response = util_load_mock("test_data/opnsense_firmware_status.mock") requests_mock.get("https://opnsense.mockserver.com/api/core/firmware/status/", json=mock_response) client = Client(MOCK_PARAMETERS) response = firmware_status_command(client) assert response[0].outputs_prefix == "OPNSense.Firmware" assert response[0].outputs["product_id"] == "opnsense" def test_opnsense_firmware_upgradestatus(requests_mock): from OPNSense import Client, firmware_upgradestatus_command mock_response = util_load_mock("test_data/opnsense_firmware_upgradestatus.mock") requests_mock.get("https://opnsense.mockserver.com/api/core/firmware/upgradestatus/", json=mock_response) client = Client(MOCK_PARAMETERS) response = firmware_upgradestatus_command(client) assert response[0].outputs_prefix == "OPNSense.Firmware" assert response[0].outputs["status"] == "done" def test_opnsense_firmware_update(requests_mock): from OPNSense import Client, firmware_update_command mock_response = {"status": "ok", "msg_uuid": "f6dbee27-431f-4574-a017-6823e1a9b631"} requests_mock.post("https://opnsense.mockserver.com/api/core/firmware/update", json=mock_response) client = Client(MOCK_PARAMETERS) response = firmware_update_command(client) assert response[0].outputs_prefix == "OPNSense.Firmware" assert response[0].outputs == {"status": "ok", "msg_uuid": "f6dbee27-431f-4574-a017-6823e1a9b631"} def test_opnsense_firmware_upgrade(requests_mock): from OPNSense import Client, firmware_upgrade_command mock_response = {"status": "ok", "msg_uuid": "a55216fb-0877-4c15-ab77-8afb78f4841b"} requests_mock.post("https://opnsense.mockserver.com/api/core/firmware/upgrade", json=mock_response) client = Client(MOCK_PARAMETERS) response = firmware_upgrade_command(client) assert response[0].outputs_prefix == "OPNSense.Firmware" assert response[0].outputs == {"status": "ok", "msg_uuid": "a55216fb-0877-4c15-ab77-8afb78f4841b"}