Поиск интерфейса по его Description
-
Добрый день.
Как можно проводить поиск по конкретным значениям какого-либо параметра в нодах?
В ветке Делимся скриптами сразу в шапке имелся скрипт поиска "в данном случае по snmp sysDescription коммутатора"sub GetTree (nodeID) { Tree = FindObject(nodeID); children = GetObjectChildren(Tree); foreach (n : children) { //println ("Name: " . n->name); if (n->name != null && classof(n) == "Node") { if (n->sysDescription ~= "^D-Link DES-3028" && n->comments == "") { println ("Name: " . n->name . ", sysDescription: " . n->sysDescription . ", IP: " . n->ipAddr); } } GetTree(n->id); } } GetTree(2);Который я попытался перенаправить на поиск нод, в которых Description на каком-то из интерфейсов имеет WAN.
sub GetTree (nodeID) { Tree = FindObject(nodeID); children = GetObjectChildren(Tree); foreach (n : children) { //println ("Name: " . n->name); if (n->name != null && classof(n) == "Node") { if (n->interfaces.description ~= "WAN" && n->comments == "") { println ("Name: " . n->name . ", interfaces.description: " . n->interfaces.description . ", IP: " . n->ipAddr); } } GetTree(n->id); } } GetTree(2);Но оба скрипта падают в syntax error на линию 13. Что с того момента изменилось в синтаксе?
=================
Edited
В таком видеsub GetTree(nodeID) { Tree = FindObject(nodeID); children = GetObjectChildren(Tree); foreach (n : children) { if (n->name != null && classof(n) == "Node") { ifaces = n->interfaces; foreach (iface : ifaces) { if (iface->description ~= "WAN") { println("Name: " , n->name , ", interface: " , iface->description , ", IP: " , iface->ipAddr); } } GetTree(n->id); } } } GetTree(2);выполнение его проходит, но результат никакой не получается
*** FINISHED *** Result: -
function GetTree(nodeID) { obj = FindObject(nodeID); if (obj == null) return; children = obj.children; for (n : children) { if (classof(n) == "Node") { ifaces = n.interfaces; for (iface : ifaces) { if (iface.description ~= "WAN") { println("Node: " .. n.name .. ", Interface: " .. iface.name .. ", Description: " .. iface.description .. ", IP: " .. iface.ipAddr); } } } // Рекурсия ВЫНЕСЕНА за пределы условия - обходим все контейнеры GetTree(n.id); } } GetTree(2);Основные изменения:
- function вместо sub — современный синтаксис
- obj.children вместо GetObjectChildren(obj)
- . вместо -> для доступа к свойствам
- .. для конкатенации строк (вместо , в println)
- Рекурсия вынесена за пределы условия classof(n) == "Node"
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login