====== Mini status Dashboard to switch WWAN links ====== The netmodule SDK allows to to add addtional web-pages to the status section of the webinterface. In this article, you will learn how to setup the dashboard sdk-script that provides the ability to switch between wanlinks and reboot the router. The new added page will look like this: {{ :app-notes:dashboard.png?800 |}} ===== Prerequierments ===== * NRSW 4.6.0.105 or NRSW 4.8.0.102 ===== Installation ===== If you dont have the required software version please install it first. ==== Adding the SDK script ==== Open the netmodule webinterface and navigate to: Services -> SDK -> Job Management === Add a SDK trigger === In this case, we want to start the dashboard at the startup, so we use an event based trigger; sdk-startup {{ :app-notes:dashboard-trigger.png?800 |}} === Add the SDK script === In the script tab copy and paste the sdk script. {{ :app-notes:dashboard-script.png?800 |}} ID = 1; hotlink = ""; string pp_var(var) { tmp=tolower(var); tmp=explode(tmp); tmp[0] = toupper(tmp[0]); for (i=0; iup'; case "good": return 'good'; case "excelent": return 'excelent'; case "dialing": return 'dialing'; case "medium": return 'medium'; case "weak": return 'weak'; case "down": return 'down'; } return value; } void print_table(array fields) { nb_page_respond(page, '\n'); nb_page_respond(page, ''); for (i=0; i < length(fields); i++) { nb_page_respond(page, '\n'); nb_page_respond(page, '', sprintf("%s", pp_var(substr(fields[i], 9)))); nb_page_respond(page, sprintf("", pp(struct_get(wan, fields[i])))); nb_page_respond(page, '\n'); } nb_page_respond(page, '
'); nb_page_respond(page, left(fields[0], 8)); nb_page_respond(page, ''); if (struct_get(wan, "WAN_HOTLINK") != left(fields[0], 8) ) { nb_page_respond(page, '
'); nb_page_respond(page, sprintf("",left(fields[0], 8))); nb_page_respond(page, '
'); } nb_page_respond(page, '
%s%s
\n'); nb_page_respond(page, '
\n'); } /* register page */ page = nb_userpage_register(ID, "Wanlink", "Switch"); if (is_void(page)) { printf("unable to register page\n"); exit(1); } while (1) { printf("waiting for requests...\n"); /* wait for page request */ request = nb_page_request(page); if (!is_void(request)) { /* evaluate GET params */ GET = struct_get(request, "GET"); } for (k = 0; k < length(GET); k++) { key = struct_get(GET[k], "key"); if (key == "hotlink") { hotlink = struct_get(GET[k], "value"); } if (key == "action") { action = struct_get(GET[k], "value"); if (action == "reboot") nb_reboot(0); } } if (hotlink != "") { nb_wanlink_priorize(hotlink, 2); sleep(5); } fields = mkarray(); wan = nb_status("wan"); for (i=1; i <=9; i++) { wan_state = struct_get(wan, sprintf("WANLINK%d_STATE", i)); wan_idx = sprintf("WANLINK%d", i); if (strlen(wan_state) > 0) { // Attributes for WWAN link wan_array = mkarray(sprintf("%s_STATE", wan_idx), sprintf("%s_TYPE", wan_idx), sprintf("%s_SIGNAL_LEVEL", wan_idx), sprintf("%s_SIGNAL_QUALITY", wan_idx), sprintf("%s_SERVICE_TYPE", wan_idx), sprintf("%s_NETWORK", wan_idx) ); // Attributes for ETH/LAN link eth_array = mkarray(sprintf("%s_STATE", wan_idx), sprintf("%s_TYPE", wan_idx), sprintf("%s_ADDRESS", wan_idx), sprintf("%s_GATEWAY", wan_idx) ); type = struct_get(wan, sprintf("WANLINK%d_TYPE", i)); switch (type) { case "eth": tmp_array = eth_array; break; case "wwan": tmp_array = wan_array; break; } fields[i-1] = tmp_array; } } nb_page_respond(page, '\n'); nb_page_respond(page, '\n'); nb_page_respond(page, ''); nb_page_respond(page, sprintf("", struct_get(wan, "WAN_HOTLINK"))); nb_page_respond(page, '
Hotlink%s
\n'); nb_page_respond(page, '
\n'); nb_page_respond(page, '\n'); nb_page_respond(page,'\n'); nb_page_respond(page, '
Reebot
\n'); nb_page_respond(page, '
\n'); for (j=0; j === Create a SDK job === Once we have the trigger and the script, we can create job that will be exected. {{ :app-notes:dashboard-job.png?800 |}} === Enable netmodule SDK === The last step is to enable the sdk. SERVICES -> SDK -> Administation {{ :app-notes:dashboard-enable-sdk.png?800 |}} ===== Check your installation ===== After the sdk has been started, you should have a new status page. Navigate to HOME -> Overwiev -> Interfaces {{ :app-notes:dashboard.png?800 |}} The page might look diffrent, depending on your number of wanlinks. ==== Switch to another wanlink ==== Your current hotlink is displayed at the top. Also, each enabled wanlink will be listet on the new status page. All links, except for the current hotlink, have a button "Use as hotlink". This can be used to change the current hotlink. This may take some time, sometimes the hotlink will be shown as "n/a". Reload the page and the new hotlink will be displayed. ==== Reboot the Router ==== The page has a reboot button. The device will reboot after 5 seconds. ==== Extend the info for a wanlink ==== You can add/remove the fields that are shown. // Attributes for WWAN link wan_array = mkarray(sprintf("%s_STATE", wan_idx), sprintf("%s_TYPE", wan_idx), sprintf("%s_SIGNAL_LEVEL", wan_idx), sprintf("%s_SIGNAL_QUALITY", wan_idx), sprintf("%s_SERVICE_TYPE", wan_idx), sprintf("%s_NETWORK", wan_idx) ); // Attributes for ETH/LAN link eth_array = mkarray(sprintf("%s_STATE", wan_idx), sprintf("%s_TYPE", wan_idx), sprintf("%s_ADDRESS", wan_idx), sprintf("%s_GATEWAY", wan_idx) ); For all attributes, use the shell command "cli status -s wan": ~ $ cli status -s wan WAN_HOTLINK="WANLINK1" WANLINK1_STATE="up" WANLINK1_STATE_IPV4="up" WANLINK1_STATE__SINCE="2023-10-30 13:59:16" WANLINK1_TYPE="eth" WANLINK1_INTERFACE="LAN1-1" WANLINK1_ADDRESS="10.0.0.189" WANLINK1_GATEWAY="10.0.0.1" WANLINK1_ADDRESS_IPV6="n/a" WANLINK1_DIAL_ATTEMPTS="1" WANLINK1_DIAL_SUCCESS="1" WANLINK1_DIAL_FAILURES="0" WANLINK1_DATA_DOWNLOADED="69869" WANLINK1_DATA_UPLOADED="63414" WANLINK1_DATA_SINCE="2023-10-30 10:41:50" WANLINK1_DOWNLOAD_RATE="0" WANLINK1_UPLOAD_RATE="0" WANLINK2_STATE="down" WANLINK2_STATE__SINCE="startup" WANLINK2_TYPE="wwan" WANLINK2_INTERFACE="WWAN1" WANLINK2_ADDRESS="n/a" WANLINK2_ADDRESS_IPV6="n/a" WANLINK2_MODEM="Mobile1" WANLINK2_SIM="SIM2" WANLINK2_PDP="PDP1" WANLINK2_SIGNAL_STRENGTH="-103" WANLINK2_SIGNAL_LEVEL="16" WANLINK2_SIGNAL_QUALITY="bad" WANLINK2_REGISTRATION_STATE="searchingNetwork" WANLINK2_SERVICE_TYPE="EDGE" WANLINK2_NETWORK="n/a" WANLINK2_DIAL_ATTEMPTS="0" WANLINK2_DIAL_SUCCESS="0" WANLINK2_DIAL_FAILURES="0" WANLINK2_DATA_DOWNLOADED="n/a" WANLINK2_DATA_UPLOADED="n/a" WANLINK2_DATA_SINCE="2023-10-30 10:43:00" WANLINK2_DOWNLOAD_RATE="0" WANLINK2_UPLOAD_RATE="0" Thats it. Enjoy your new status page.