Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Perl script for capturing SNMP Alerts.

by pritesh_ugrankar (Scribe)
on Sep 12, 2020 at 09:26 UTC ( #11121655=perlquestion: print w/replies, xml ) Need Help??

pritesh_ugrankar has asked for the wisdom of the Perl Monks concerning the following question:

Respected Monks,

I have written perl scripts to automate some health check on various storage devices. To that end, I find Perl extremely flexible and sheer joy to code in.

However, I am now planning to write a script that will monitor the storage device and if any failure occurs, it will send out an email. I have very basic idea of how SNMP works and I have been through the Net::SNMP documentation, but not sure how it will talk to the SNMP server, or will ports 161, 162 need to be opened from / to the server on which the script is running & the SNMP Server?

Please note, I am not looking for ready made code. I just need pointers.

I just realized that I need to read up on SNMP as well to really understand how it works, but in the interim, any pointers you provide will be a great help. I was here a long time ago and you folks had suggested some truly amazing modules and some great pointers...hoping for the same this time too.

Replies are listed 'Best First'.
Re: Perl script for capturing SNMP Alerts.
by hippo (Chancellor) on Sep 12, 2020 at 10:34 UTC
    not sure how it will talk to the SNMP server, or will ports 161, 162 need to be opened from / to the server on which the script is running & the SNMP Server?

    For the purposes of the monitor/alert, the box where your script runs will be the SNMP client and the box you are monitoring will be the SNMP server. It is the SNMP server which must allow inbound UDP traffic on port 161 from the SNMP client.

    If you are looking for some code for inspiration I would suggest MTRG which is widely used, written in Perl and runs over SNMP. You may even find you can just use MRTG to do all you need anyway.


    🦛

Re: Perl script for capturing SNMP Alerts.
by Fletch (Chancellor) on Sep 12, 2020 at 22:37 UTC

    In the interest of not reinventing wheels you might also look into Nagios which has off the shelf support for monitoring with SNMP and is (fairly) easily extensible with whatever other language in which you want to indulge (including perl which is what several of the stock checks are written in).

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

      Hi Fletch,

      Thank you for the information. Extra thanks for pointing out that my favourite language is still being used and not as abandoned as the online hype seems to portray. The language and this community both are a refuge for someone like me who is not a trained professional programmer, but someone who likes scripting (Perl scripting especially) to automate stuff and have fun while doing it.

Re: Perl script for capturing SNMP Alerts.
by pritesh_ugrankar (Scribe) on Sep 13, 2020 at 11:08 UTC

    Respected Monks, Thank you for the suggestions and guidance.

Re: Perl script for capturing SNMP Alerts.
by perlfan (Priest) on Sep 14, 2020 at 16:17 UTC
    I think it has an API (perfect for perl to hit), but you may want to checkout Observium (and also nagios, as mentioned already).
Re:Perl script for capturing SNMP Alerts.
by jahero (Pilgrim) on Sep 16, 2020 at 12:38 UTC

    DISCLAIMER: this is strictly not what you asked for. Apology.

    Some time ago, I have had to solve the problem of sending a notification about failures from a batch job which was executed every 5 minutes or so, and had success with simple Slack app. You might want to check https://metacpan.org/pod/Slack::Notify.

    Conceptually, this is what you would do:

    1. Create a Slack workspace
    2. Create a channel within the workspace
    3. Create a Slack app
    4. Enable incoming webhooks on the app
    5. Enjoy the module

    The advantage of this approach is that you can get push notification directly to your mobile phone, via Slack.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://11121655]
Approved by marto
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2020-09-20 07:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (120 votes). Check out past polls.

    Notices?