UNPKG

@gapit/node-red-contrib-gapit-snmp

Version:

A Node-RED node which gets SNMP OIDs based on the gapit code JSON schema.

227 lines (219 loc) 11.1 kB
<script type="text/html" data-template-name="gapit-snmp"> <div class="form-row"> <label for="node-input-host"><i class="fa fa-globe"></i> Host</label> <input type="text" id="node-input-host" placeholder="ip address(:optional port)"> </div> <div class="form-row"> <label for="node-input-version"><i class="fa fa-bookmark"></i> Version</label> <select type="text" id="node-input-version" style="width:150px;"> <option value="1">v1</option> <option value="2c">v2c</option> <option value="3">v3</option> </select> <span style="margin-left:50px;">Timeout</span> <input type="text" id="node-input-timeout" placeholder="secs" style="width:50px; direction:rtl; vertical-align:baseline;">&nbsp;S </div> <div class="form-row snmpoptions snmpoptions_v1 snmpoptions_v2c"> <label for="node-input-community"><i class="fa fa-user"></i> Community</label> <input type="text" id="node-input-community" placeholder="public"> </div> <div class="form-row snmpoptions snmpoptions_v3"> <label for="node-input-context"><i class="fa fa-filter"></i> Context</label> <input type="text" id="node-input-context" placeholder="SNMPv3 context - can be empty"> </div> <div class="form-row snmpoptions snmpoptions_v3"> <label for="node-input-username"><i class="fa fa-user"></i> Username</label> <input type="text" id="node-input-username" placeholder="SNMPv3 username"> </div> <div class="form-row snmpoptions snmpoptions_v3"> <label for="node-input-security_level"><i class="fa fa-shield"></i> Security level</label> <select type="text" id="node-input-security_level"> <option value="authPriv">authPriv</option> <option value="authNoPriv">authNoPriv</option> <option value="noAuthNoPriv">noAuthNoPriv</option> </select> </div> <div class="form-row snmpoptions snmpoptions_v3 snmpoptions_v3_sec snmpoptions_v3_sec_authNoPriv snmpoptions_v3_sec_authPriv"> <label for="node-input-auth_protocol"><i class="fa fa-shield"></i> Auth Procol</label> <select type="text" id="node-input-auth_protocol"> <option value="md5">MD5</option> <option value="sha">SHA</option> </select> </div> <div class="form-row snmpoptions snmpoptions_v3 snmpoptions_v3_sec snmpoptions_v3_sec_authNoPriv snmpoptions_v3_sec_authPriv"> <label for="node-input-auth_key"><i class="fa fa-user-secret"></i> Auth Key</label> <input type="password" id="node-input-auth_key" placeholder="SNMPv3 auth key"> </div> <div class="form-row snmpoptions snmpoptions_v3 snmpoptions_v3_sec snmpoptions_v3_sec_authPriv"> <label for="node-input-priv_protocol"><i class="fa fa-shield"></i> Privacy Protocol</label> <select type="text" id="node-input-priv_protocol"> <option value="des">DES</option> <option value="aes">AES-128</option> <option value="aes256r">AES-256 ("Reeder" key localization)</option> <option value="aes256b">AES-256 ("Blumenthal" key localization)</option> </select> </div> <div class="form-row snmpoptions snmpoptions_v3 snmpoptions_v3_sec snmpoptions_v3_sec_authPriv"> <label for="node-input-priv_key"><i class="fa fa-user-secret"></i> Privacy Key</label> <input type="password" id="node-input-priv_key" placeholder="SNMPv3 priv key"> </div> <div class="form-row"> <label for="node-input-tagvalue_device_name"><i class="fa fa-file-code-o"></i> Device name</label> <input type="text" id="node-input-tagvalue_device_name" /> </div> <div class="form-row"> <label for="node-input-tagname_device_name"><i class="fa fa-file-code-o"></i> Device name db-tag</label> <input type="text" id="node-input-tagname_device_name" /> </div> <div class="form-row"> <label for="node-input-minion_ids"><i class="fa fa-ellipsis-h"></i> Minion IDs</label> <input type="text" id="node-input-minion_ids" placeholder="0;1;2"> </div> <div class="form-row"> <label for="node-input-custom_tags"><i class="fa fa-ellipsis-h"></i> Custom tags</label> <input type="text" id="node-input-custom_tags" placeholder="0;1;2"> </div> <div class="form-row"> <label for="node-input-gapit_code"><i class="fa fa-file-code-o"></i> Gapit code</label> <input type="text" id="node-input-gapit_code" /> </div> <div class="form-row"> <label for="node-input-scaling"><i class="fa fa-tag"></i> Scaling</label> <input type="text" id="node-input-scaling"> </div> <div class="form-row"> <label for="node-input-skip_nonexistent_oids"><i class="fa fa-remove"></i> Skip nonexistent OIDs in subsequent queries</label> <input type="checkbox" id="node-input-skip_nonexistent_oids" /> </div> <div class="form-row"> <label for="node-input-remove_novalue_items_from_gapit_results"><i class="fa fa-remove"></i> Remove items with no value from gapit_results</label> <input type="checkbox" id="node-input-remove_novalue_items_from_gapit_results" /> </div> <div class="form-row"> <label for="node-input-convert_counter64_bigint_to_number"><i class="fa fa-remove"></i> Convert Counter64 BigInt to Number if possible</label> <input type="checkbox" id="node-input-convert_counter64_bigint_to_number" /> </div> <div class="form-row"> <label for="node-input-name"><i class="fa fa-tag"></i> Name</label> <input type="text" id="node-input-name" placeholder="Name"> </div> <div class="form-tips"> <p> <b>Tip:</b> If multiple devices are queried via a single SNMP server, their IDs may be specified in the <i>Minion IDs</i> field, separated by <i>;</i> (semicolon). In this case, an equal number of <i>Device name</i>s must also be specified (also separated by <i>;</i>). (Querying multiple devices via one SNMP server is implemented by using OIDs where one of the segments of the OID is variable, representing the device ID. This is represented by "x" in OIDs in the Gapit code.) </p> <p> <b>Custom tags</b><br /> Add database tags, formatted as JSON with tag_name: value. If multiple minions are specified, tags must be in a child object named for the device name, or "all-minion-tags" for any tags that should be common for all minions. </p> <p> <b>Counter64 notes</b><br /> Conversion from BigInt to Number is attempted by default. (Only numbers which are small enough to be represented as a JavaScript Number are converted.) InfluxDB 2 has a UInteger type (64-bit unsigned), but this is not supported by <i>node-red-contrib-influxdb</i> (as of v0.6.1). If you are using something other than InfluxDB (or a future version of <i>node-red-contrib-influxdb</i> where this works), you may want to uncheck *Convert Counter64 BigInt to Number if possible*. </p> </div> </script> <script type="text/html" data-help-name="gapit-snmp"> <p>Simple SNMP oid or oid list fetcher. Triggered by any input.</p> <p><code>msg.host</code> may contain the host.</p> <p><code>msg.community</code> may contain the community.</p> <p>OIDs must be numeric. iso. is the same a 1. </p> <p>The node will output <code>msg.payload</code> and <code>msg.oid</code>.</p> </script> <script type="text/javascript"> RED.nodes.registerType('gapit-snmp', { category: 'network-input', color: "YellowGreen", credentials: { username: {type:"text"}, auth_key: {type:"password"}, priv_key: {type:"password"} }, defaults: { host: { value: "127.0.0.1" }, community: { value: "public" }, version: { value: "1", required: true }, context: { value: "" }, security_level: { value: "authPriv" }, auth_protocol: { value: "sha" }, priv_protocol: { value: "des" }, tagname_device_name: { value: "device_name", required: true }, tagvalue_device_name: { value: "default_name", required: true }, minion_ids: { value: "" }, custom_tags: { value: "" }, gapit_code: { value: "" }, scaling: { value: "general" }, skip_nonexistent_oids: { value: true }, remove_novalue_items_from_gapit_results: { value: true }, convert_counter64_bigint_to_number: { value: true }, timeout: { value: 5 }, name: { value: "" } }, inputs: 1, outputs: 1, icon: "snmp.png", label: function () { return this.name || "gapit-snmp " + this.host; }, labelStyle: function () { return this.name ? "node_label_italic" : ""; }, oneditprepare: function () { // field customization $("#node-input-custom_tags").typedInput({ type:"json", types:["json"] }); $("#node-input-gapit_code").typedInput({ type:"json", types:["json"] }); $("#node-input-scaling").typedInput({ types: [ { value: "general", options: [ { value: "general", label: "General"}, { value: "schleifenbauer", label: "Schleifenbauer"}, ] } ] }); ///// dynamic UI // // hide fields based on SNMP version $("#node-input-version").on("change", function() { let version = $("#node-input-version").val(); let optionsClass = `.snmpoptions_v${version}`; $(".snmpoptions").hide(); $(optionsClass).show(); }); // hide fields based on SNMP security level $("#node-input-security_level").on("change", function() { let securityLevel = $("#node-input-security_level").val(); let levelClass = `.snmpoptions_v3_sec_${securityLevel}`; $(".snmpoptions_v3_sec").hide(); $(levelClass).show(); }); // Trigger change events for initial form setup. // Doesn't seem to work when called immediately, // so use a timer (even 1 msec seems to work). setTimeout(function() { $("#node-input-security_level").triggerHandler("change"); $("#node-input-version").triggerHandler("change"); }, 1); }, }); </script>