Skip to content

Commit 07cd112

Browse files
committed
Add support for SNMP input type with detailed options and usage documentation
1 parent 1d55ed6 commit 07cd112

File tree

5 files changed

+209
-603
lines changed

5 files changed

+209
-603
lines changed

data/completion.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,21 @@ complete:
155155
desc: If true instead of returning a SQL AST representation it will beautify the SQL statements
156156
- name: sqloptions=
157157
desc: A JSON/SLON map with options for sqlparse=true
158+
- name: in=snmp
159+
desc: Retrieves data from a SNMP device
160+
opts:
161+
- name: insnmp=
162+
desc: The SNMP address 'udp://1.2.3.4/161'
163+
- name: insnmpcommunity=
164+
desc: The SNMP community
165+
- name: insnmpversion=
166+
desc: The SNMP version -1, 2, 3-
167+
- name: insnmptimeout=
168+
desc: The SNMP timeout
169+
- name: insnmpretries=
170+
desc: The SNMP retries
171+
- name: insnmpsec=
172+
desc: JSON/SLON map with SNMPv3 security options
158173
- name: in=toml
159174
desc: TOML format
160175
- name: in=xls

data/usage.json

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,18 @@
154154
"Input type": "ini",
155155
"Description": "INI/Properties format"
156156
},
157+
{
158+
"Input type": "javas",
159+
"Description": "Tries to list java processes running locally (javainception=true to include itself)"
160+
},
157161
{
158162
"Input type": "javagc",
159163
"Description": "The Java GC log lines text format"
160164
},
165+
{
166+
"Input type": "jmx",
167+
"Description": "Uses Java JMX to retrieve data from another Java process"
168+
},
161169
{
162170
"Input type": "json",
163171
"Description": "A JSON format (auto-detected)"
@@ -226,6 +234,10 @@
226234
"Input type": "slon",
227235
"Description": "A SLON format (auto-detected)"
228236
},
237+
{
238+
"Input type": "snmp",
239+
"Description": "A SNMP device source"
240+
},
229241
{
230242
"Input type": "sql",
231243
"Description": "One or more SQLs statements to AST (Abstract Syntax Tree) or beautified SQL"
@@ -633,6 +645,56 @@
633645
"Description": "If true it will return an array with each processed line."
634646
}
635647
],
648+
[
649+
{
650+
"Option": "jmxpid",
651+
"Type": "Number",
652+
"Description": "The local java process pid to connect to if 'jmxurl' is not provided."
653+
},
654+
{
655+
"Option": "jmxurl",
656+
"Type": "String",
657+
"Description": "The JMX URL to connect to if 'jmxpid' is not provided."
658+
},
659+
{
660+
"Option": "jmxuser",
661+
"Type": "String",
662+
"Description": "The JMX user to use if JMX URL was provided."
663+
},
664+
{
665+
"Option": "jmxpass",
666+
"Type": "String",
667+
"Description": "The JMX password to use if JMX URL was provided."
668+
},
669+
{
670+
"Option": "jmxprovider",
671+
"Type": "String",
672+
"Description": "The JMX provider Java class if JMX URL was provided."
673+
},
674+
{
675+
"Option": "jmxop",
676+
"Type": "String",
677+
"Description": "The operation to perform (see below for options)"
678+
}
679+
],
680+
[
681+
{
682+
"Op": "all",
683+
"Description": "Tries to retrieve all JMX data available."
684+
},
685+
{
686+
"Op": "domains",
687+
"Description": "Retrieves just a list of JMX domains available."
688+
},
689+
{
690+
"Op": "query",
691+
"Description": "Performs a JMX query from the input data provided (e.g. java.lang:*)"
692+
},
693+
{
694+
"Op": "get",
695+
"Description": "Retrieves a specific JMX object (e.g. java.lang:type=Memory)"
696+
}
697+
],
636698
[
637699
{
638700
"Option": "jsondesc",
@@ -744,6 +806,64 @@
744806
"Description": "The format to parse stdout and stderr between raw, yaml or json (default)"
745807
}
746808
],
809+
[
810+
{
811+
"Option": "insnmp",
812+
"Type": "String",
813+
"Description": "A SNMP address in the form 'udp://1.2.3.4/161'"
814+
},
815+
{
816+
"Option": "insnmpcommunity",
817+
"Type": "String",
818+
"Description": "The SNMP community to use (default 'public')"
819+
},
820+
{
821+
"Option": "insnmptimeout",
822+
"Type": "Number",
823+
"Description": "The timeout to wait for a reply"
824+
},
825+
{
826+
"Option": "insnmpretries",
827+
"Type": "Number",
828+
"Description": "Number of retries in case of failure"
829+
},
830+
{
831+
"Option": "insnmpversion",
832+
"Type": "Number",
833+
"Description": "Version of the SNMP server (e.g. 2, 3)"
834+
},
835+
{
836+
"Option": "insnmpsec",
837+
"Type": "String",
838+
"Description": "A JSON/SLON representation of security attributes (see below)"
839+
}
840+
],
841+
[
842+
{
843+
"Entry": "securityName",
844+
"Description": "The security name to use"
845+
},
846+
{
847+
"Entry": "authProtocol",
848+
"Description": "One of: HMAC128SHA224, HMAC192SHA256, HMAC256SHA384, HMAC384SHA512, MD5, SHA"
849+
},
850+
{
851+
"Entry": "privProtocol",
852+
"Description": "One of: 3DES, AES128, AES192, AES256, DES"
853+
},
854+
{
855+
"Entry": "authPassphrase",
856+
"Description": "The authorization passphrase to use"
857+
},
858+
{
859+
"Entry": "privPassphrase",
860+
"Description": "The private passphrase to use"
861+
},
862+
{
863+
"Entry": "engineId",
864+
"Description": "The engine id in hexadecimal format"
865+
}
866+
],
747867
[
748868
{
749869
"Option": "sqlparse",

src/docs/USAGE.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ List of data input types that can be auto-detected (through the file extension o
9090
| rawhex | Tries to read the input char by char converting into lines with the hexadecimal representation |
9191
| sh | Executes a shell command returning stdout, stderr and exitcode as a map |
9292
| slon | A SLON format (auto-detected) |
93+
| snmp | A SNMP device source |
9394
| sql | One or more SQLs statements to AST (Abstract Syntax Tree) or beautified SQL |
9495
| toml | TOML format |
9596
| xls | A XLSx compatible file (requires file=abc.xlsx) |
@@ -367,6 +368,39 @@ The input data map can be composed of:
367368

368369
---
369370

371+
### 🧾 SNMP input options
372+
373+
List of options to use when _in=snmp_:
374+
375+
| Option | Type | Description |
376+
|--------|------|-------------|
377+
| insnmp | String | A SNMP address in the form 'udp://1.2.3.4/161' |
378+
| insnmpcommunity | String | The SNMP community to use (default 'public') |
379+
| insnmptimeout | Number | The timeout to wait for a reply |
380+
| insnmpretries | Number | Number of retries in case of failure |
381+
| insnmpversion | Number | Version of the SNMP server (e.g. 2, 3) |
382+
| insnmpsec | String | A JSON/SLON representation of security attributes (see below) |
383+
384+
The input data can be either:
385+
386+
* A single string with an OID
387+
* Multiple lines each with just an OID
388+
* An array of OID strings
389+
* A map with OID string values
390+
391+
The 'insnmpsec' (in case of version 3 or newer) entry should be a JSON/SLON map with:
392+
393+
| Entry | Description |
394+
|-------|-------------|
395+
| securityName | The security name to use |
396+
| authProtocol | One of: HMAC128SHA224, HMAC192SHA256, HMAC256SHA384, HMAC384SHA512, MD5, SHA |
397+
| privProtocol | One of: 3DES, AES128, AES192, AES256, DES |
398+
| authPassphrase | The authorization passphrase to use |
399+
| privPassphrase | The private passphrase to use |
400+
| engineId | The engine id in hexadecimal format |
401+
402+
---
403+
370404
### 🧾 SQL input options
371405

372406
List of options to use when _in=sql_:

src/include/inputFns.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,46 @@ var _inputFns = new Map([
829829
}
830830
_$o(_r, options)
831831
}],
832+
["snmp", (_res, options) => {
833+
_$(params.insnmp, "insnmp").isString().$_()
834+
params.insnmpcommunity = _$(params.insnmpcommunity, "insnmpcommunity").isString().default("public")
835+
params.insnmptimeout = _$(params.insnmptimeout, "insnmptimeout").isNumber().default(__)
836+
params.insnmpretries = _$(params.insnmpretries, "insnmpretries").isNumber().default(__)
837+
params.insnmpversion = _$(params.insnmpversion, "insnmpversion").isString().default(__)
838+
params.insnmpsec = _fromJSSLON(_$(params.insnmpsec, "insnmpsec").isString().default(__))
839+
_showTmpMsg()
840+
plugin("SNMP")
841+
var snmp = new SNMP(params.insnmp, params.insnmpcommunity, params.insnmptimeout, params.insnmpversion, params.insnmpsec)
842+
let _r = {}, _i = _fromJSSLON(_res)
843+
if (isString(_i)) {
844+
var _p = _i.split("\n").map(p => p.trim()).filter(p => p.length > 0)
845+
if (_p.length == 1) {
846+
_r = snmp.get(_res)
847+
if (isMap(_r)) _r = _r[_res]
848+
} else {
849+
_r = pForEach(_p, p => {
850+
var _r = snmp.get(p)
851+
if (isMap(_r)) _r = _r[p]
852+
return _r
853+
})
854+
}
855+
} else {
856+
let _ism = isMap(_i)
857+
ow.loadObj()
858+
var _fn = _oid => snmp.get(_oid)[_oid]
859+
if (_ism) {
860+
let _ac = []
861+
_r = _i
862+
traverse(_r, (aK, aV, aP, aO) => {
863+
if (isString(aV)) _ac.push({ o: aO, k: aK, v: aV })
864+
})
865+
pForEach(_ac, ac => ac.o[ac.k] = _fn(ac.v))
866+
} else {
867+
_r = pForEach(_i, a => _fn(a))
868+
}
869+
}
870+
_$o(_r, options)
871+
}],
832872
["ls", (_res, options) => {
833873
_showTmpMsg()
834874
if (isString(_res)) {

0 commit comments

Comments
 (0)