Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - Millenium7

#16
I'm trying to use SSH to push commands to devices through netXMS
I'm using $node->executeSSHCommand to push commands, but how do I use multiple lines of text? I know on MikroTik I can separate commands with a semi-colon, i.e.

$node->executeSSHCommand(":log warning test;:log warning test2;:log warning test3");

This isn't viable for very long commands especially those with scripts in them that might be 50 lines or more. I can't compress them into a single line
So how do I do something like....

$node->executeSSHCommand("
:log warning test
:log warning test2
:log warning test3
");


Or even inside a variable

MyBigScript = {
:log warning test
:log warning test2
:log warning test3
};
$node->executeSSHCommand(MyBigScript);


This syntax is not valid in NetXMS. So how do I do it? I need SSH scripts to be human readable and editable. Impossible with very long single liners
#17
Is there a way to either 'discover' if an OID returns a valid result and if so, use it? I.e. that way I can create a 'Wireless - ALL' template that applies to every single radio in our network, and the same DCI applies to them, but it sets the OID correctly (I don't think I want to use a script type DCI though because it would create a lot of unnecessary SNMP polling on every poll)

Alternatively can I again create a 'Wireless - ALL' template and create an additional script type DCI, and it simply checks for which DCI's already exist? Or better yet, detects the device make/model (already do that with specific templates for all the manufacturers/models we use) and then points to the appropriate DCI?

Just not sure how to go about it. My pseudo-code I imagine looking something like this

if DeviceManufacturer == "Ubiquiti" then...
...if DeviceModelType == "AirMAX" then use the value from DCI with OID .1.3.6.1.4.1.41112.1.4.1.1.4.1
...if DeviceModelType == "AirFiber" then use the value from DCI with OID .1.3.6.1.4.1.41112.1.3.1.1.5.1
if DeviceManufacturer == "MikroTik" then...
...if DeviceModelType == "60ghz" then use the value from DCI with OID .1.3.6.1.4.1.14988.1.1.1.8.1.6.1
etc etc


So that way every radio ends up with 2 DCI's
1 with the correctly applied OID from the discovery script for that specific make/model
And another with the name of "Radio (Universal) - Tx Frequency"
#18
Otherwise here's a sample of what I use for Cambium ePMP series (all of them, not just 3000 specifically)

// ePMP series
if ($node->snmpOID ~= "(.1.3.6.1.4.1.17713.21.9).*") return true;


#19
Just a guess but I think you need to return a 'true' or 'false' in order for it work
And it could be that your RegEx syntax is wrong?

Maybe try "ePMP3000 \(FCC\)" the backslashes mean a literal '(' or ')' otherwise () implies a capture group
You could also try "ePMP3000.*" if you don't care about it having to exactly have "(FCC)" on the end
#20
We have many different vendors equipment in our network that have different OID's for the same value
I.e. radio frequency on cambium ePMP radio's is a different OID to Ubiquiti AirFiber for example
I have created templates for all the radio's, and they all pull the data for each vendor/model

However I want to have a common DCI for all of them, so that when I run scripts or summary tables I can use a common 'Center Frequency' DCI and not have to create 1 for all the different DCI's
If this makes any sense?
How do I go about that? I'm guessing I have to create another DCI with type Script and then have a script run and find which DCI's exist on that node and use it? But I don't know the correct way to do this without causing potential script errors
#21
Hmm it definitely isn't the case
I did check 'Prevent automatic SNMP changes' and that is not enabled

I'll get back to you with config output, but right now if I change SNMP string on the device, it will forever fail polling in NetXMS until I either manually update the SNMP string in NetXMS to match, or I delete the node and wait 24hrs for automatic network discovery again
#22
Often we install equipment with many default values including SNMP string of 'public' and at a later time we go and update them. Problem is if NetXMS has discovered the device during this install phase it will be assigned 'public' as the SNMP string, it will never discover it again. So of course after we change it a bit later on, NetXMS will continually fail to retrieve anything from that device

Is there a way via script or other built-in method that after a node has failed to poll any data after multiple retries (or a whole day) it will re-try all the credentials listed under Network Credentials?

#23
At the moment it's not possible to select more than 1 node and do most things with the right click menu
I.e. I can't select 5 nodes and choose Poll->Configuration
Instead I have to do it 1 by 1 which is very tedious
It would be nice if these options were allowed

And being able to set common options for multiple selected nodes at the same time would also be great. I.e. selecting 17 different nodes nodes, right click->properties go to polling menu
- 'Disable usage of NetXMS agent'
- 'Disable usage of EtherNet/IP'
- Prevent automatic SNMP changes
- Comment "Test Lab Equipment"
- Custom Attributes -> add -> AttributeXYZ
- etc

Doing this manually 1 at a time is very slow and painful
#24
Found the problem with new nodes being added automatically in wrong site

That's actually not the problem. It was that NetXMS was grouping /32 loopback addresses into a /24 subnet which contained a lot of other routers. I deleted the subnet (maybe a misconfiguration earlier?) and that solved the issue

I've also tested your code samples above and its immensely helpful in drilling through possible variables, lot in there I didn't even know about, now it makes significantly more sense and i'll be able to craft some better scripts. Thank you
#25
Excellent, that helps a lot, thank you

I would like to see a better write-up in the wiki/documentation (or even a pinned post here, or a separate scripting section) that goes further into explaining the scripting language and actual applications of it, with much more samples and details on how/why

Like what you posted

Quote from: Victor Kirhenshtein on February 16, 2021, 10:04:49 AM

5. It is possible to dump all attributes and methods of an object. For example, to dump all attributes of $node:

for(a : $node->__class->attributes)
   println(a . " = " . $node->__get(a));

or all methods:

for(m : $node->__class->methods)
   println(m);



That is immensely helpful, and is foundation level stuff that should be explained in the documentation to help navigate around what commands to use, but how/why/when to use them
Same thing with debug output, that's been my biggest hurdle with NetXMS and so many hours lost trying to get things working. The commands are written up with a few examples, but not enough attention to actually putting them into practice and how/why you would use them, and most importantly a write-up on debugging and troubleshooting to show people where to go when something doesn't work
I often feel like i've been given a hammer and some nails, told how to use them, but the lights are off so the best I can do is guess where they should go. Having a few torches to help light the room up would be nice
#26
1 downside to both scripts however
When discovering/adding a new node to NetXMS. It appears to bind to all of the folders using these scripts. So something is causing an immediate match upon the first discovery poll....
#27
Whew, finally after several hours of fighting the syntax, I stumbled my way across the line

I was also confused by your first line, why is it even there? I get that the match statement is to use a regex to extract $1 as the router name, but wouldn't it always return true? as its just tested itself against..... itself, right?

Anyway here's the script I finally came up with. I'm using a custom attribute on the folder/container itself called 'SeedRouter' and I put the ID of the router I want to use as the seed object. This fits our purposes better than a name (Since i've configured NetXMS to automatically refresh names if the router's name has been changed, that would screw up this auto binding)

t = GetCustomAttribute($container, "SeedRouter");
if (t == null) return false;
SeedRouter = FindObject(t);
if (SeedRouter == null) return false;
trace(0,"Custom Attribute = ".t); // Debug, show value of 'SeedRouter' in container
trace(0,"Seed Router name = ".SeedRouter->name); // Debug, show name of router matching that ID
if ($node == SeedRouter->name) return true; // If node being tested matches seed, return true and save some CPU cycles
for(rp : SeedRouter->parents)
{
   if (classof(rp) == "Subnet")
   {
for(np : $node->parents)
   if (np->id == rp->id)   // Same object
      return true;
   }
}
return false;


The only way I finally got any useful debugging was to kill the netxmsd service and re-run it as an application in Linux. Then trace level 0 worked to display output in the SSH window. However this clearly isn't the most practical way to do it as I don't want to restart the instance every time I start to work on a script
I use the web interface and I can see it is missing the Console output window. I presume I could have also used that if it was there? Problem is the latest Windows Management Binary is broken and errors out on launch (tried on 2 different PC's)
#28
Thanks, though its not working for me just yet
It is working I had the name slightly wrong

On a side tangent. How exactly do I go about troubleshooting scripts and syntax 'effectively'? It's something i've constantly struggled with NetXMS script writing because I can't progressively step through and troubleshoot all the variables and operations 1 by 1, but maybe there is a way to do this?
For instance the very first line

if (not ($container->name match "^Site:(.*)"))

How do I troubleshoot this by seeing what $container is returning? and what (.*) is? (I know what it is but assume I just want to see the output for troubleshooting purposes) This would HUGELY help me troubleshoot it
I thought I could just put commands above it like
trace(0,$container);
trace(0,$node);
But nothing shows up in Event Monitor (where else could I see it?)
The only way i've done this in the past is using 'Execute Server Script' on a node/container and I use 'println' to give me some output and I work from there. But this doesn't work in a live script, and sometimes that's the only method. Like right now because it relies on variables like $container which don't exist when using 'Execute Server Script'

To put it simply: How do you go about troubleshooting your scripts? Assume I am doing everything completely wrong, can you please tell me exactly where to go and what to do to step through a script line by line and troubleshoot it correctly.
I can figure out the syntax and fumbly my way through if I know what all the variables are doing, but if I don't have that then I just spend an hour guessing randomly hoping the thing works, and if it doesn't I have no idea where its failing when it could be as simple as using $1 instead of $node or vice-versa
#29
Not quite what i'm looking for because a router might have 12 different subnets. So browsing subnet by subnet is not reallyeffective
I'd rather see something like a router also acting like a folder, which you can expand out and it shows all the devices in the same subnet as that router. If that makes sense?

Or another tab in 'Object Details' called 'Subnets' with a tree view containing them and all devices in that same subnet (if also in the same Zone as that router)
#30
Is there an easy intuitive method for seeing/filtering all devices within a local subnet of a router?