aluisiora / routeros-client Goto Github PK
View Code? Open in Web Editor NEWAbstraction layer over the node-routeros API
License: MIT License
Abstraction layer over the node-routeros API
License: MIT License
Hi,
I use this package with node.js using socket.io to communicate with server. I received data perfectly, but after a few seconds my app stoped and show me error.
RosException
at Connector.onError (……/node_modules/node-routeros/dist/connector/Connector.js:169:15)
at Socket.emit (events.js:321:20)
at emitErrorNT (internal/streams/destroy.js:84:8)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
name: 'RosException',
errno: -104
}
I get this error when trying to connect using a user name and password that works on the web UI of the mikrotik.
I have this code to get information from server. But when I switch to the second server still first server remain active and (TotalClients) code bring me data for both servers (one time for the first server and another time for the second server) in each 5 seconds. How I can stop reading from one server and listing just for second server.
`
const RouterOSClient = require('routeros-client').RouterOSClient
let api
serverConnection = (data) => {
return new RouterOSClient({
host: data.host,
user: data.user,
password: data.password,
keepalive: true,
timeout: 50
})
}
socket.on('TotalClients', (serverData, status) => {
if(status == true) {
api = serverConnection(serverData)
api.connect().then(client => {
client.menu("/ppp secret")
.query({ interval: 5 })
.stream('print', (err, data) => {
if(data.length > 0) io.emit('Clients-Length', data.length)
})
})
} else {
if(api) {
const closing = api.rosApi.closing
if(!closing) api.close()
}
}
})
})
`
Expand methods like update, remove, unset and etc to accept a where
query and use that to retrieve the entries ids to run the commands. Goal is to achieve something like this:
addressMenu
.where("address", "192.168.88.15/24")
.orWhere("address", "192.168.15.88/24")
.remove();
Hi, i trying torch pppoe interface but does not work
const RouterOSClient = require("routeros-client").RouterOSClient;
const routeros = new RouterOSClient({
host: process.env.SERVER_HOST,
user: process.env.SERVER_USER,
password: process.env.SERVER_PASSWORD,
});
routeros
.connect()
.then((client) => {
const torchMenu = client.menu("/ppp torch")
.where({interface: "<pppoe-test_client>"})
.stream((err, data) => {
if (err) console.log(err)
console.log(data)
})
})
.catch((err) => {
console.log("Error: ", err);
});
Hello.
How to prepare config for multiple connections(lists with hosts, passwords, etc.)?
When using this library with the where filter to do updates, remove, delete there is a bug that just returns some random result from that menu if the where the filter is not true.
I now have to use get on any resource before invoking update, remove or delete
Hi, I wrote this code to get Tx-Packets and Rx-Packets.
const RouterOSClient = require('routeros-client').RouterOSClient
const api = new RouterOSClient({
host: process.env.SERVER_HOST,
user: process.env.SERVER_USER,
password: process.env.SERVER_PASSWORD,
keepalive: true
})
api.connect().then(client => {
const torchMenu = client.menu("/tool torch")
.where({interface: "WAN-1"})
.stream((err, data) => {
if (err) console.log(err)
console.log(data)
})
})
This code shows error:
TypeError: this.debounceSendingEmptyData is not a function.
Could you please help me to solve this issue.
Hi guys looking to use the speed-test tool in the API
I get it to work just fine and returns a array of all the sections of the test but what i would like is to actuality be able to stream the test instead of waiting for the array of elements is this possible
This is the code i have sofar and like i say it works but ideally i need to open a stream
api.connect().then((client) => { cont test = client .menu("/tool") .exec("speed-test", { user: "user", password: "pass", address: "someip", }) .then((result) => { console.log(result); }); });
Hi,
I get this weird unhandled 'error' event and node server just crash.
Is this node or routeros-client related?
"node": "v10.4.1"
"routeros-client": "^0.11.0"
events.js:167
throw er; // Unhandled 'error' event
^
RosException: Timed out after 10 seconds
at Connector.onTimeout (/var/app/node_modules/node-routeros/dist/connector/Connector.js:181:30)
at Object.onceWrapper (events.js:273:13)
at Socket.emit (events.js:182:13)
at Socket._onTimeout (net.js:444:8)
at ontimeout (timers.js:427:11)
at tryOnTimeout (timers.js:289:5)
at listOnTimeout (timers.js:252:5)
at Timer.processTimers (timers.js:212:10)
Emitted 'error' event at:
at RouterOSAPI.rosApi.once (/var/app/node_modules/routeros-client/dist/RouterOSClient.js:33:53)
at Object.onceWrapper (events.js:273:13)
at RouterOSAPI.emit (events.js:182:13)
at Connector.connectedErrorListener (/var/app/node_modules/node-routeros/dist/RouterOSAPI.js:103:30)
at Object.onceWrapper (events.js:273:13)
at Connector.emit (events.js:182:13)
at Connector.onTimeout (/var/app/node_modules/node-routeros/dist/connector/Connector.js:181:14)
at Object.onceWrapper (events.js:273:13)
at Socket.emit (events.js:182:13)
at Socket._onTimeout (net.js:444:8)
Thanks for help!
So, I've created a record:
/ip hotspot user add server all name user1 password 123456789 profile default
then I'm trying to delete it:
api.connect().then((client) => {
client.menu("/ip hotspot user").where("name", "user1").remove().then((response) => {
console.log(response);// response is an array of all items removed
}).catch((err) => {
// Error getting the list of firewall filter entries
console.log(err);
});
});
{
'$$path': '/ip/hotspot/user',
id: '*B',
name: 'user1',
password: 123456789,
profile: 'default',
uptime: '0s',
bytesIn: 0,
bytesOut: 0,
packetsIn: 0,
packetsOut: 0,
dynamic: false,
disabled: false
}
Response: true
events.js:292
throw er; // Unhandled 'error' event
^
RosException: Timed out after 10 seconds
at Connector.onTimeout (C:\Users\user\Desktop\temp\node_modules\node-routeros\dist\connector\Connector.js:187:30)
at Object.onceWrapper (events.js:421:28)
at Socket.emit (events.js:315:20)
at Socket._onTimeout (net.js:482:8)
at listOnTimeout (internal/timers.js:549:17)
at processTimers (internal/timers.js:492:7)
Emitted 'error' event on RouterOSClient instance at:
at RouterOSAPI. (C:\Users\user\Desktop\temp\node_modules\routeros-client\dist\RouterOSClient.js:34:53)
at Object.onceWrapper (events.js:422:26)
at RouterOSAPI.emit (events.js:315:20)
at Connector.connectedErrorListener (C:\Users\user\Desktop\temp\node_modules\node-routeros\dist\RouterOSAPI.js:105:30)
at Object.onceWrapper (events.js:422:26)
at Connector.emit (events.js:315:20)
at Connector.onTimeout (C:\Users\user\Desktop\develop\temp\node_modules\node-routeros\dist\connector\Connector.js:187:14)
at Object.onceWrapper (events.js:421:28)
at Socket.emit (events.js:315:20)
at Socket._onTimeout (net.js:482:8) {
errno: 'SOCKTMOUT'
}
a log records in routerOS:
00:00:00 system,info hotspot user user1 removed by admin
00:00:00 system,info,account user admin logged out from 192.168.1.254 via api
Thank you for the routerOS client! Well done! It's just what the doctor ordered! :D
const RouterOSClient = require('routeros-client').RouterOSClient;
const api = new RouterOSClient({
host: 'https://************:12',
user: '*****',
password: '********',
});
api
.connect()
.then(async (client) => {
// Connection successful
console.log('Connection Successful');
await api.close();
})
.catch((err) => {
// Got an error while trying to connect
console.log(err);
});
$ node index.js
RosException
at Connector.onError (E:\Projects\mikrotek-test\node_modules\node-routeros\dist\connector\Connector.js:176:15)
at Socket.emit (events.js:210:5)
at emitErrorNT (internal/streams/destroy.js:92:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
at processTicksAndRejections (internal/process/task_queues.js:80:21) {
name: 'RosException',
errno: 'ENOTFOUND'
}
Hi This is more a question than an issue
I need to pull the interface CCQ I use to do this via php_api but now a use node
so id like to move away from the PHP if I can
Is it at all possible to get the information from
menu('/interface/wireless/monitor') or something in that line allmost :-)
I try doing this using node-routeros as well can't seem to be able to get it there is either
i was tying to use this package with create-react-app with typescript, at the time of compilation everything goes right, but when i try to use, lets say this simple login function
import { IRosOptions, RouterOSClient } from 'routeros-client';
const login = async (cred: IRosOptions) => {
const api = new RouterOSClient({ ...cred });
try {
const conn = await api.connect();
if (api.isConnected()) api.disconnect();
return true;
} catch (error) {
throw error;
}
};
i got this error:
TypeError: net_1.Socket is not a constructor
at Connector.connect (Connector.js:85)
at RouterOSAPI.js:137
at new Promise (<anonymous>)
at RouterOSAPI.connect (RouterOSAPI.js:100)
at RouterOSClient.connect (RouterOSClient.js:41)
at login (MikrotikAPI.ts:19)
at Login.handleLogin (Login.tsx:55)
at HTMLUnknownElement.callCallback (react-dom.development.js:147)
at Object.invokeGuardedCallbackDev (react-dom.development.js:196)
at invokeGuardedCallback (react-dom.development.js:250)
at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:265)
at executeDispatch (react-dom.development.js:571)
at executeDispatchesInOrder (react-dom.development.js:596)
at executeDispatchesAndRelease (react-dom.development.js:695)
at executeDispatchesAndReleaseTopLevel (react-dom.development.js:704)
at forEachAccumulated (react-dom.development.js:676)
at runEventsInBatch (react-dom.development.js:844)
at runExtractedEventsInBatch (react-dom.development.js:852)
at handleTopLevel (react-dom.development.js:5029)
at batchedUpdates$1 (react-dom.development.js:21463)
at batchedUpdates (react-dom.development.js:2247)
at dispatchEvent (react-dom.development.js:5109)
at react-dom.development.js:21520
at Object.unstable_runWithPriority (scheduler.development.js:255)
at interactiveUpdates$1 (react-dom.development.js:21519)
at interactiveUpdates (react-dom.development.js:2268)
at dispatchInteractiveEvent (react-dom.development.js:5085)
even if i change the syntax to old require as in the examples like this
import { IRosOptions } from 'routeros-client';
const { RouterOSClient } = require('routeros-client').RouterOSClient;
const login = async (cred: IRosOptions) => {
const api = new RouterOSClient({ ...cred });
try {
const conn = await api.connect();
if (api.isConnected()) api.disconnect();
return true;
} catch (error) {
throw error;
}
};
i got this error
TypeError: RouterOSClient is not a constructor
at login (MikrotikAPI.ts:6)
at Login.handleLogin (Login.tsx:55)
at HTMLUnknownElement.callCallback (react-dom.development.js:147)
at Object.invokeGuardedCallbackDev (react-dom.development.js:196)
at invokeGuardedCallback (react-dom.development.js:250)
at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:265)
at executeDispatch (react-dom.development.js:571)
at executeDispatchesInOrder (react-dom.development.js:596)
at executeDispatchesAndRelease (react-dom.development.js:695)
at executeDispatchesAndReleaseTopLevel (react-dom.development.js:704)
at forEachAccumulated (react-dom.development.js:676)
at runEventsInBatch (react-dom.development.js:844)
at runExtractedEventsInBatch (react-dom.development.js:852)
at handleTopLevel (react-dom.development.js:5029)
at batchedUpdates$1 (react-dom.development.js:21463)
at batchedUpdates (react-dom.development.js:2247)
at dispatchEvent (react-dom.development.js:5109)
at react-dom.development.js:21520
at Object.unstable_runWithPriority (scheduler.development.js:255)
at interactiveUpdates$1 (react-dom.development.js:21519)
at interactiveUpdates (react-dom.development.js:2268)
at dispatchInteractiveEvent (react-dom.development.js:5085)
im trying to make this work with React and typescript
This is something i was trying to handle with some regex extracting the values that the API returns and add the time i want for example:
let's say that i have a user in the hotspot which returns the value
limitUptime='1d12h'
but if i want to increase that limit with something like limitUptime + "1h"
isn't possible without lots of manually regex, split and join methods for that string, so a helper function for this would be a realive.
Im trying create a new user with this code but doesnt work
const RosApi = require('node-routeros').RouterOSAPI;
const conn = new RosApi({
host: '10.99.99.4',
user: 'admin',
password: '',
});
const data ={
username:'test',
password:'testt',
customer:'ADMIN'
}
conn.connect()
.then(() => {
const d = [
'=name='+data.username,
'=password='+data.password,
'=customer='+data.customer,
];
conn.write('tool/user-manage/user/add', d )
.then((data) => {
console.log('OK');
})
.catch((err) =>{
console.log('Error')
})
})
.catch((err) => {
// Got an error while trying to connect
console.log(err);
});```
Compilation error with TypeScript 2.9.2:
node_modules/routeros-client/dist/RosApiModel.d.ts:35:5 - error TS2416: Property 'move' in type 'RosApiModel' is not assignable to the same property in base type 'RouterOSAPICrud'.
Type '(to?: string | number | undefined) => Promise<any>' is not assignable to type '(from: Id, to?: string | number | undefined) => Promise<any>'.
Types of parameters 'to' and 'from' are incompatible.
Type 'Id' is not assignable to type 'string | number | undefined'.
Type '(string | number)[]' is not assignable to type 'string | number | undefined'.
Type '(string | number)[]' is not assignable to type 'number'.
35 move(to?: string | number): Types.SocPromise;
~~~~
My dependencies in package.json are:
"devDependencies": {
"@types/node": "^10.5.1",
"@types/serialize-error": "^2.1.0",
"rimraf": "^2.6.2",
"typescript": "^2.9.2"
},
"dependencies": {
"influx": "^5.0.7",
"routeros-client": "^0.10.1",
"serialize-error": "^2.1.0"
}
Other than the above, the package is working fine.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.