Custom graph generator

Hi there,

I need to develop a custom graphs integrated in librenms.

Looking at all possibilities I’ve been able to make run I decided to create a SNMP extension…

I began by creating my bash script that reads from someplace inside /var/log compute data and give me a number (basic case)

I placed that script inside /etc/snmp/ make it executable (chmod +x)…

Then I’ve added this feature as an extension in snmpd.conf

extend script /etc/snmp/script.sh

Then I restarted snmpd service.

To get correct OID I used this commands:

$ snmptranslate -On 'NET-SNMP-EXTEND-MIB::nsExtendOutLine."script".1'
.1.3.6.1.4.1.8072.1.3.2.4.1.2.13.111.100.111.111.45.114.101.113.117.101.115.116.115.1

After that I send a request from my LibreNMS server to my monitor system in this 2 ways.

snmpget -u bootstrap -l authPriv -a MD5 -x DES -A temp_password -X temp_password 172.18.0.1 'NET-SNMP-EXTEND-MIB::nsExtendOutLine."script".1'
NET-SNMP-EXTEND-MIB::nsExtendOutLine."script".1 = STRING: 1.2
 
snmpget -u bootstrap -l authPriv -a MD5 -x DES -A temp_password -X temp_password 172.18.0.1 .1.3.6.1.4.1.8072.1.3.2.4.1.2.13.111.100.111.111.45.114.101.113.117.101.115.116.115.1
NET-SNMP-EXTEND-MIB::nsExtendOutLine."script".1 = STRING: 1.2

At this point I noticed in this way couldn’t reach to a solution:

So I’m here to ask a little bit about th widescreen of libreNMS and how I would be capable of develop this necessity.

My goal is to create a plugin/app/module/whatever that can read from SNMP(or other way) and display data in graphs.

Which way should I take?

Thanks!

The best help you’ll get on this might be looking at what someone else has done:

Thanks! :grinning:

I’ve tried to follow some documentation, polling seems is working.
https://docs.librenms.org/#Developing/os/Custom-Graphs/

includes/definitions.inc.php

$config['graph_types']['device']['sample_script']['section']         = 'system';
$config['graph_types']['device']['sample_script']['order']           = '0';
$config['graph_types']['device']['sample_script']['descr']           = 'Request per minute';

include/polling/os/sample.inc.php

<?php

use LibreNMS\RRD\RrdDefinition;

$requests = snmp_get($device, 'script.1');

if (is_numeric($requests)) {
    $rrd_def = RrdDefinition::make()->addDataset('requests', 'GAUGE', 0);

    $fields = array(
            'requests' => $requests,
        );

    $tags = compact('rrd_def');
    data_update($device, 'sample_script', $tags, $fields);
    $graphs['sample_script'] = true;
}

I’ve updated my database

mysql --user=root -p
USE librenms;
INSERT INTO `graph_types`(`graph_type`, `graph_subtype`, `graph_section`, `graph_descr`, `graph_order`) VALUES ('device',  'sample_script',  'system',  'Requests per min',  0);

Added:
html/includes/graphs/device/sample_script.inc.php

<?php

$rrd_filename = rrd_name($device['hostname'], 'sample_script');

require 'includes/graphs/common.inc.php';

$ds = 'requests';

$colour_area = '9999cc';
$colour_line = '0000cc';

$colour_area_max = '9999cc';

$graph_max = 1;
$graph_min = 0;

$unit_text = 'requests';

require 'includes/graphs/generic_simplex.inc.php';

Once I configured all this data is not shown in my WebUI.
How could I debug this code? In particular snmp_get function.
I’m also wonder which is refresh time for this polling.