internet_module v1.0.3
NETWORK MANAGER
Version 1.0.1
Review 13-04-2021
Table of Contents
Database
- In order to save the configuration settings and log the requests this module use Mysql database
- All the sql scripts are available inside database folder
- create_db_defaults.sql
- procedures.sql
- triggers.sql
- events.sql
- views.sql
- Create user and grant access
CREATE USER your_username IDENTIFIED BY 'your_password';
ALTER user 'your_username' IDENTIFIED WITH mysqlnative_password BY **'yourpassword';
GRANT EXECUTE
ON network_manager.*
TO 'your_username'**;
- Create environment variables
- NM_HOST
- NM_USER
- NM_PASSWORD
Config
commands
All OS commands for Linux and MacOS are available on this file.
Most commands for MacOS provide dummy data.
logger
Log level (from from more to less comprehensive)
1. info
2. warn
3. error
- Create environment variable for log level
- NM_LOG_LEVEL
Interfaces
Interfaces
// Define the expected interfaces
const expected_interfaces = 'wlan0', 'eth0';
// Intantiate Interfaces class
const interfaces = new Interfaces(expected_interfaces); // List all available interfaces on the device
interfaces.listInterfaces()
.then(result => {
console.log(result);
})
.catch(err => {
console.log(err);
});
Wifi
// Intantiate Wifi class
const wifi = new Wifi();
// Restart Wifi interface
wifi.restartInterface()
.then(result => {
console.log(result);
})
.catch(err => {
console.log(err);
});
Ethernet
// Intantiate Ethernet class
const ethernet = new Ethernet();
// Verify if ethernet cable is plugged
ethernet.cablePlug()
.then(result => {
console.log(result);
})
.catch(err => {
console.log(err);
});
Validate Interfaces
This module with follow a workflow that use the Interfaces module to verify if the device have available interfaces.
// Requires
const { Interfaces, Wifi, Ethernet } = require('interfaces');
const validateInterfaces = require('validateInterfaces');
// Instances
const interfaces = new Interfaces('wlan0', 'eth0'); // Interfaces available
const wifi = new Wifi();
const ethernet = new Ethernet();
// Validate interfaces
validateInterfaces.checkInterfaces(interfaces, wifi, ethernet)
.then(result => {
console.log("Have valid interface!");
})
.catch(err => {
console.log("Doesn't a valid interface");
});
This module is based on the following workflow
Axios Request
This module will send and handle the requests
Configuration for the request
- Method:
Request type (GET, POST, PUT, DELETE) - Address:
Request URL - Request Level:
1 - If it fails, does nothing
2 - Save on pending if fails
3 - Save the request. Save on pending if fails
// Config for the request
const config = {
method: 'GET',
address: 'localhost:3000',
request_level: 2
}
// Headers
const headers = {
test: 'teste123'
}
await axiosRequest(config, headers)
.then(response => {
console.log(response);
})
.catch(err => {
console.log(err);
})
Speed Test
This module instatiate a class that receive an array of addresses as parameters and can request all the addresses and order them based on queue and then response time
// Instantiate the class
const speedtest = new SpeedTest("http://192.168.1.191:3000", "http://192.168.1.191:3001", "http://192.168.1.191:3002");
speedtest.axiosList()
.then(res => {
console.log(speedtest.orderAxios(res));
}) .catch(err => {
console.log(err);
});