The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Sagan::Monitoring - LibreNMS JSON SNMP extend and Nagios style check for Sagan stats

VERSION

Version 1.2.0

SYNOPSIS

    use Sagan::Monitoring;

    my $args = {
        mode               => 'librenms',
        drop_percent_warn  => .75;
        drop_percent_crit  => 1,
        files=>{
               'ids'=>'/var/log/sagan/alert-ids.json',
               'foo'=>'/var/log/sagan/alert-foo.json',
               },
    };

    my $sm=Sagan::Monitoring->new( $args );
    my $returned=$sm->run;
    $sm->print;
    exit $returned->{alert};

METHODS

new

Initiate the object.

The args are taken as a hash ref. The keys are documented as below.

The only must have is 'files'.

This assumes that stats-json.subtract_old_values is set to 'true' for Sagan.

    - drop_percent_warn :: Drop percent warning threshold.
      - Default :: .75;
        
    - drop_percent_crit :: Drop percent critical threshold.
      - Default :: 1
        
    - files :: A hash with the keys being the instance name and the values
      being the Eve files to read. ".total" is not a valid instance name.
      Similarly anything starting with a "." should be considred reserved.

    - max_age :: How far back to read in seconds.
      - Default :: 360

    - mode :: 'librenms' or 'nagios' as to how to print the output.
      - Default :: librenms

    my $args = {
        drop_percent_warn  => .75;
        drop_percent_crit  => 1,
        mode               => 'librenms',
        max_age            => 360,
        files=>{
               'ids'=>'/var/log/sagan/stats-ids.json',
               'foo'=>'/var/log/sagan/stats-foo.json',
               },
    };

    my $sm=Sagan::Monitoring->new( $args );

run

This runs it and collects the data. Also updates the cache.

This will return a LibreNMS style hash.

    my $returned=$sm->run;

Prints the output. $sm->print_output;

LibreNMS HASH

    + $hash{'alert'} :: Alert status.
      - 0 :: OK
      - 1 :: WARNING
      - 2 :: CRITICAL
      - 3 :: UNKNOWN
    
    + $hash{'alertString'} :: A string describing the alert. Defaults to
      '' if there is no alert.
    
    + $hash{'error'} :: A integer representing a error. '0' represents
      everything is fine.
    
    + $hash{'errorString'} :: A string description of the error.
    
    + $hash{'data'}{$instance} :: Values migrated from the
      instance. Non *_percent values are created via computing the difference
      from the previously saved info. *_percent is based off of the delta
      in question over the packet delta. Delta are created for packet,
      drop, ifdrop, and error. Percents are made for drop, ifdrop, and
      error.
    
    + $hash{'data'}{'.total'} :: Total values of from all the
      intances. Any percents will be recomputed.
    

    The stat keys are migrated as below.
    
    uptime              => $json->{stats}{uptime},
    total               => $json->{stats}{captured}{total},
    drop                => $json->{stats}{captured}{drop},
    ignore              => $json->{stats}{captured}{ignore},
    threshold           => $json->{stats}{captured}{theshold},
    after               => $json->{stats}{captured}{after},
    match               => $json->{stats}{captured}{match},
    bytes               => $json->{stats}{captured}{bytes_total},
    bytes_ignored       => $json->{stats}{captured}{bytes_ignored},
    max_bytes_log_line  => $json->{stats}{captured}{max_bytes_log_line},
    eps                 => $json->{stats}{captured}{eps},
    f_total             => $json->{stats}{flow}{total},
    f_dropped           => $json->{stats}{flow}{dropped},

AUTHOR

Zane C. Bowers-Hadley, <vvelox at vvelox.net>

BUGS

Please report any bugs or feature requests to bug-sagan-monitoring at rt.cpan.org, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Sagan-Monitoring. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Sagan::Monitoring

You can also look for information at:

"Sagan-Monitoring.git" in git@github.com:VVelox

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

This software is Copyright (c) 2022 by Zane C. Bowers-Hadley.

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)

3 POD Errors

The following errors were encountered while parsing the POD:

Around line 555:

Unknown directive: =head

Around line 559:

'=item' outside of any '=over'

Around line 563:

You forgot a '=back' before '=head1'