Este exemplo baseia-se em nossos posts anteriores Exemplo minimalista NodeJS Mikrotik API e MikroTik RouterOS: Como fazer power-cycle de PoE usando o terminal.
O seguinte código irá imprimir o status do PoE na Porta ether5 no dispositivo MikroTik dado usando a API MikroTik.
mikrotik_poe_status_example.js
import * as MikroNode from 'mikrotik' ;
const host = "192.168.88.1";
const username = "admin";
const password = "admin1234"; // Espero que essa não seja sua senha real ;)
const connection = MikroNode.getConnection(host, username, password, {
closeOnDone : true
});
connection.getConnectPromise().then(function(conn) {
conn.getCommandPromise(['/interface/ethernet/poe/print', '?name=ether5']).then(values => {
console.log(values);
}, reason => {
console.log('Erro ao executar o comando: ' + JSON.stringify(reason));
});
}).catch(reason => {
console.log('Erro ao conectar: ' + JSON.stringify(reason));
});Saída de exemplo:
example_output.json
[
{
'.id': '*5',
name: 'ether5',
'poe-out': 'forced-on',
'poe-priority': '10',
'poe-lldp-enabled': 'false',
'power-cycle-ping-enabled': 'false',
'power-cycle-interval': 'none',
'.about': 'poe-out status: power_reset'
}
]Se o PoE estiver atualmente em power-cycle, isso imprimirá:
poe_power_cycle_output.json
[
{
'.id': '*5',
name: 'ether5',
'poe-out': 'forced-on',
'poe-priority': '10',
'poe-lldp-enabled': 'false',
'power-cycle-ping-enabled': 'false',
'power-cycle-interval': 'none',
'.about': 'poe-out status: power_reset'
}
]If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow