File tree 10 files changed +6341
-4830
lines changed
10 files changed +6341
-4830
lines changed Original file line number Diff line number Diff line change 1
1
.vscode /
2
2
node_modules /
3
+ .yarn /
3
4
package-lock.json
4
5
/pkg
5
6
/pkg.tgz
Original file line number Diff line number Diff line change
1
+ nodeLinker : node-modules
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ To configure this module you will need:
9
9
1 . Agent Address - The IP Address of the SNMP enabled device you want to control
10
10
2 . UDP Port - The number of the UDP port on which the agent is listening (defaults to port 161)
11
11
3 . SNMP Version - The version of SNMP used by the agent. This will dictate how this module will authenticate with the agent
12
+ 4 . Poll Interval - The poll interval for Get OID actions with update enabled.
12
13
13
14
#### SNMP versions v1/v2c
14
15
@@ -41,6 +42,7 @@ If you selected SNMP version `v3` you will also need to configure the following:
41
42
42
43
You can perform the following actions with this module:
43
44
45
+ - Get OID value, return to custom variable
44
46
- Set OID value to an OctetString
45
47
- Set OID value to a Number. This includes the following SNMP Object Types:
46
48
- Integer
Original file line number Diff line number Diff line change
1
+ import { generateEslintConfig } from '@companion-module/tools/eslint/config.mjs'
2
+
3
+ const baseConfig = async ( ) => {
4
+ await generateEslintConfig ( { } )
5
+ }
6
+
7
+ const customConfig = [
8
+ ...baseConfig ,
9
+ {
10
+ languageOptions : {
11
+ sourceType : 'module' ,
12
+ } ,
13
+ } ,
14
+ ]
15
+
16
+ export default customConfig
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " generic-snmp" ,
3
- "version" : " 2.0 .0" ,
3
+ "version" : " 2.1 .0" ,
4
4
"main" : " src/index.js" ,
5
- "sourceType " : " module" ,
5
+ "type " : " module" ,
6
6
"scripts" : {
7
7
"test" : " echo \" Error: no test specified\" && exit 1" ,
8
8
"format" : " prettier -w ." ,
9
9
"eslint" : " eslint" ,
10
- "semantic-release" : " semantic-release"
10
+ "lint" : " eslint" ,
11
+ "semantic-release" : " semantic-release" ,
12
+ "package" : " companion-module-build"
11
13
},
12
14
"dependencies" : {
13
15
"@companion-module/base" : " ~1.10.0" ,
14
- "net-snmp" : " ^3.12.1 "
16
+ "net-snmp" : " ^3.15.0 "
15
17
},
16
18
"devDependencies" : {
17
- "@companion-module/tools" : " ^2.0.0 " ,
19
+ "@companion-module/tools" : " ^2.0.4 " ,
18
20
"@semantic-release/changelog" : " ^6.0.3" ,
19
21
"@semantic-release/git" : " ^10.0.1" ,
20
22
"eslint" : " ^8.1.0" ,
25
27
"repository" : {
26
28
"type" : " git" ,
27
29
"url" : " git+https://github.com/bitfocus/companion-module-generic-snmp.git"
28
- }
30
+ },
31
+ "prettier" : " @companion-module/tools/.prettierrc.json" ,
32
+ "packageManager" :
" [email protected] "
29
33
}
Original file line number Diff line number Diff line change @@ -183,6 +183,41 @@ export default async function (self) {
183
183
self . setOid ( oid , snmp . ObjectType . oid , value )
184
184
} ,
185
185
}
186
+ actionDefs [ 'getOID' ] = {
187
+ name : 'Get OID value' ,
188
+ options : [
189
+ {
190
+ type : 'textinput' ,
191
+ label : 'OID' ,
192
+ id : 'oid' ,
193
+ default : '' ,
194
+ required : true ,
195
+ useVariables : true ,
196
+ regex : Regex . SOMETHING ,
197
+ } ,
198
+ {
199
+ type : 'custom-variable' ,
200
+ label : 'Variable' ,
201
+ id : 'variable' ,
202
+ tooltip : 'Custom Variable that OID value is returned to' ,
203
+ } ,
204
+ {
205
+ type : 'checkbox' ,
206
+ label : 'Update' ,
207
+ id : 'update' ,
208
+ tooltip : 'Update each poll interval' ,
209
+ default : false ,
210
+ } ,
211
+ ] ,
212
+ callback : async ( { options } ) => {
213
+ self . getOid ( await self . parseVariablesInString ( options . oid ) , options . variable )
214
+ } ,
215
+ subscribe : async ( { options } ) => {
216
+ if ( options . update ) {
217
+ self . getOid ( await self . parseVariablesInString ( options . oid ) , options . variable )
218
+ }
219
+ } ,
220
+ }
186
221
187
222
self . setActionDefinitions ( actionDefs )
188
223
}
Original file line number Diff line number Diff line change @@ -133,5 +133,16 @@ export function getConfigFields() {
133
133
default : '' ,
134
134
isVisible : ( { version, securityLevel } ) => version === 'v3' && securityLevel === 'authPriv' ,
135
135
} ,
136
+ {
137
+ type : 'number' ,
138
+ id : 'interval' ,
139
+ label : 'Poll Interval' ,
140
+ width : 6 ,
141
+ min : 0 ,
142
+ max : 3600 ,
143
+ default : 0 ,
144
+ required : true ,
145
+ tooltip : 'Set to 0 to turn polling off.' ,
146
+ } ,
136
147
]
137
148
}
Original file line number Diff line number Diff line change @@ -19,11 +19,21 @@ class Generic_SNMP extends InstanceBase {
19
19
this . config = config
20
20
this . updateActions ( )
21
21
this . connectAgent ( )
22
+ if ( this . config . interval > 0 ) {
23
+ this . pollOids ( )
24
+ }
22
25
}
23
26
24
27
async configUpdated ( config ) {
25
28
this . config = config
29
+ if ( this . pollTimer ) {
30
+ clearTimeout ( this . pollTimer )
31
+ delete this . pollTimer
32
+ }
26
33
this . connectAgent ( )
34
+ if ( this . config . interval > 0 ) {
35
+ this . pollOids ( )
36
+ }
27
37
}
28
38
29
39
connectAgent ( ) {
@@ -117,8 +127,39 @@ class Generic_SNMP extends InstanceBase {
117
127
} )
118
128
}
119
129
130
+ getOid ( oid , customVariable ) {
131
+ try {
132
+ this . session . get (
133
+ [ oid ] ,
134
+ ( ( error , varbinds ) => {
135
+ if ( error ) {
136
+ this . log ( 'warn' , `getOid error: ${ JSON . stringify ( error ) } cannot set ${ customVariable } ` )
137
+ return
138
+ }
139
+ //this.log('debug', `OID: ${varbinds[0].oid} value: ${varbinds[0].value} setting to: ${customVariable}`)
140
+ this . setCustomVariableValue ( customVariable , varbinds [ 0 ] . value )
141
+ } ) . bind ( this ) ,
142
+ )
143
+ } catch ( e ) {
144
+ this . log ( 'warn' , `getOid error: ${ JSON . stringify ( e ) } cannot set ${ customVariable } ` )
145
+ }
146
+ }
147
+
148
+ pollOids ( ) {
149
+ this . subscribeActions ( 'getOID' )
150
+ if ( this . config . interval > 0 ) {
151
+ this . pollTimer = setTimeout ( ( ) => {
152
+ this . pollOids ( )
153
+ } , this . config . interval * 1000 )
154
+ }
155
+ }
156
+
120
157
async destroy ( ) {
121
158
this . log ( 'debug' , `destroy ${ this . id } ` )
159
+ if ( this . pollTimer ) {
160
+ clearTimeout ( this . pollTimer )
161
+ delete this . pollTimer
162
+ }
122
163
this . disconnectAgent ( )
123
164
}
124
165
Original file line number Diff line number Diff line change @@ -28,4 +28,20 @@ export default [
28
28
}
29
29
return result
30
30
} ,
31
+ function v210 ( _context , props ) {
32
+ const result = {
33
+ updatedActions : [ ] ,
34
+ updatedConfig : null ,
35
+ updatedFeedbacks : [ ] ,
36
+ }
37
+ if ( props . config !== null ) {
38
+ let config = props . config
39
+ if ( config . interval == undefined || config . interval == null ) {
40
+ config . interval = 0
41
+ result . updatedConfig = config
42
+ }
43
+ }
44
+
45
+ return result
46
+ } ,
31
47
]
You can’t perform that action at this time.
0 commit comments