NodeJS MikroTik PoE 状态查询示例
此示例基于我们之前的文章 NodeJS Mikrotik API 最小示例 和 MikroTik RouterOS:如何使用终端重启 PoE。
以下代码将使用 MikroTik API 打印给定 MikroTik 设备上 ether5 端口的 PoE 状态。
mikrotik_poe_status_example.js
import * as MikroNode from 'mikrotik' ;
const host = "192.168.88.1";
const username = "admin";
const password = "admin1234"; // Hope that's not your real password ;)
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('Error while running command: ' + JSON.stringify(reason));
});
}).catch(reason => {
console.log('Error while connecting: ' + JSON.stringify(reason));
});示例输出:
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'
}
]如果 PoE 当前正在重启,这将打印:
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