Examples of usage
NBI
MikroTik
MikroTik devices offer a wide range of configuration attributes, and while many of them can be managed through CWMP (CPE WAN Management Protocol) Parameters, there may be cases where specific settings need to be altered using the powerful scripting language of RouterOS. This process allows you to configure attributes not covered by CWMP Parameters. There are two primary methods for making these changes: Alter Configuration:
- RouterOS enables you to execute scripts to modify configurations. This is achieved by utilizing the "Download RPC" with FileType="3 Vendor Configuration File" and a downloadable file extension of ".alter."
- This approach allows you to configure any RouterOS attributes that are not accessible through CWMP Parameters. You can define your custom configuration in the ".alter" file.
The example below explains how we can change DNS settings using this approach:
-
Create "testConfig.alter" file with commands
/ip dns
set allow-remote-requests=yes servers=1.1.1.1 -
Extract commands from your file and convert them to a base64 string.
Convert with bash utility:
base64 testConfig.alter
L2lwIGRucwpzZXQgYWxsb3ctcmVtb3RlLXJlcXVlc3RzPXllcyBzZXJ2ZXJzPTEuMS4xLjE= -
Upload file on your instance file server.
POST /v1/method/UploadConfig HTTP/1.1
Host: 127.0.0.1
Content-Type: application/json
{
"cpe_id": "MicroTik_Device",
"filename": "testConfig.alter",
"filecontent":"L2lwIGRucwpzZXQgYWxsb3ctcmVtb3RlLXJlcXVlc3RzPXllcyBzZXJ2ZXJzPTEuMS4xLjE="
}200 OK
{
"result": {
"code": 200,
"message": "File successfully uploaded to MicroTik_Device/testConfig.alter"
}
} -
Apply config file.
POST /v1/method/ApplyConfig HTTP/1.1
Host: 127.0.0.1
Content-Type: application/json
{
"search_options": {
"cpe_id": "MicroTik_Device"
},
"command_options": {
"async": false,
"no_cnr": false
},
"parameters": {
"path_to_config": "",
"cfg_file_name": "testConfig.alter",
"cfg_file_type": "3 Vendor Configuration File"
}
}200 OK
{
"result": {
"message": "Scenario was finished",
"code": 200,
"details": [
{
"key": "code",
"value": 200
},
{
"key": "message",
"value": "Restore config file completed, CNR reinitialized"
}
]
}
} -
Now you successfully upload and apply config on your MikroTic device