Your SlideShare is downloading. ×
0
Writing plugins for Nagios and Opsview - CAPSiDE Tech Talks
Writing plugins for Nagios and Opsview - CAPSiDE Tech Talks
Writing plugins for Nagios and Opsview - CAPSiDE Tech Talks
Writing plugins for Nagios and Opsview - CAPSiDE Tech Talks
Writing plugins for Nagios and Opsview - CAPSiDE Tech Talks
Writing plugins for Nagios and Opsview - CAPSiDE Tech Talks
Writing plugins for Nagios and Opsview - CAPSiDE Tech Talks
Writing plugins for Nagios and Opsview - CAPSiDE Tech Talks
Writing plugins for Nagios and Opsview - CAPSiDE Tech Talks
Writing plugins for Nagios and Opsview - CAPSiDE Tech Talks
Writing plugins for Nagios and Opsview - CAPSiDE Tech Talks
Writing plugins for Nagios and Opsview - CAPSiDE Tech Talks
Writing plugins for Nagios and Opsview - CAPSiDE Tech Talks
Writing plugins for Nagios and Opsview - CAPSiDE Tech Talks
Writing plugins for Nagios and Opsview - CAPSiDE Tech Talks
Writing plugins for Nagios and Opsview - CAPSiDE Tech Talks
Writing plugins for Nagios and Opsview - CAPSiDE Tech Talks
Writing plugins for Nagios and Opsview - CAPSiDE Tech Talks
Writing plugins for Nagios and Opsview - CAPSiDE Tech Talks
Writing plugins for Nagios and Opsview - CAPSiDE Tech Talks
Writing plugins for Nagios and Opsview - CAPSiDE Tech Talks
Writing plugins for Nagios and Opsview - CAPSiDE Tech Talks
Writing plugins for Nagios and Opsview - CAPSiDE Tech Talks
Writing plugins for Nagios and Opsview - CAPSiDE Tech Talks
Writing plugins for Nagios and Opsview - CAPSiDE Tech Talks
Writing plugins for Nagios and Opsview - CAPSiDE Tech Talks
Writing plugins for Nagios and Opsview - CAPSiDE Tech Talks
Writing plugins for Nagios and Opsview - CAPSiDE Tech Talks
Writing plugins for Nagios and Opsview - CAPSiDE Tech Talks
Writing plugins for Nagios and Opsview - CAPSiDE Tech Talks
Writing plugins for Nagios and Opsview - CAPSiDE Tech Talks
Writing plugins for Nagios and Opsview - CAPSiDE Tech Talks
Writing plugins for Nagios and Opsview - CAPSiDE Tech Talks
Writing plugins for Nagios and Opsview - CAPSiDE Tech Talks
Writing plugins for Nagios and Opsview - CAPSiDE Tech Talks
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Writing plugins for Nagios and Opsview - CAPSiDE Tech Talks

2,007

Published on

Presentation for CAPSiDE Tech Talks about how to write great Nagios plugins in Perl for the Nagios-compatible monitoring solution of your choice

Presentation for CAPSiDE Tech Talks about how to write great Nagios plugins in Perl for the Nagios-compatible monitoring solution of your choice

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,007
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
3
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Writing plugins for Nagios and Opsview Jose Luis Martinez CTO 2014-02-11 Barcelona architects of the digital society www.capside.com
  • 2. Nagios What is Nagios? Opsview? Icinga? Naemon? Shinken? architects of the digital society www.capside.com
  • 3. Opsview  Configures and runs Nagios for you  Presents a frendlier and more powerfull user interface  Implements Nagios best practices  Distributed Monitoring  Datawarehouse architects of the digital society www.capside.com
  • 4. Back to Nagios  Monitoring tool that doesn’t know how to monitor anything!?!? • The real monitoring is done by plugins • Just external programs with a defined interface to communicate with Nagios • Written in any language architects of the digital society www.capside.com
  • 5. Plugins architects of the digital society www.capside.com
  • 6. Writing your plugins architects of the digital society www.capside.com
  • 7. First rule  Is it already done? • www.monitoring-plugins.org • Plugins project • www.nagiosplugins.org • Nagios official plugins • www.monitoringexchange.org • User contributed • exchange.nagios.org • User contributed • Google “xxx nagios” architects of the digital society www.capside.com
  • 8. We’ll take a look at  Nagios::Plugin (Monitoring::Plugin)  Nagios::Plugin::DieNicely  Nagios::Plugin::WWW::Mechanize  Nagios::Plugin::SNMP  Nagios::Plugin::Differences architects of the digital society www.capside.com
  • 9. Nagios::Plugin  Lots of common functionality for free! • When writing a plugin you have to Handle Arguments Get and manipulate the data Calculate state (OK, CRITICAL, …) architects of the digital society www.capside.com
  • 10. Nagios::Plugin  Lots of common functionality for free! • When writing a GREAT plugin you have to Handle Arguments -h –v arguments -h has to output documentation Get and manipulate the data Calculate state (OK, CRITICAL, …) In a flexible way (in f(x) of arguments) Output performance data architects of the digital society www.capside.com
  • 11. That’s a lot of work I just wanted to monitor my app! architects of the digital society www.capside.com
  • 12. Nagios::Plugin  Lots of common functionality for free! • When writing a GREAT plugin you have to Handle Arguments -h –v arguments -h has to output documentation Get and manipulate the data Calculate state (OK, CRITICAL, …) In a flexible way (in f(x) of arguments) Output performance data architects of the digital society www.capside.com
  • 13. 3 Simple Steps  Setup  Data collection  State calculation architects of the digital society www.capside.com
  • 14. Setup  Just make an instance of N::P #!/usr/bin/env perl use Nagios::Plugin; my $np= Nagios::Plugin->new( 'usage' => 'Usage: %s' ); $np->getopts;  You’ve just obtained • -t option (timeout) • -v option (verbose) • --help option architects of the digital society www.capside.com
  • 15. Setup (II) Constructor options  usage ("Usage: %s --foo --bar")  version <- Version string  url <- Help and Version  blurb <- Help description  license <- Help  extra <- Help  plugin <- overrides auto detected name architects of the digital society www.capside.com
  • 16. Setup: GetOpt magic $np->add_arg( spec=> 'warning|w=s', help=> "-w, --warning=RANGE", required=> 1 ); $np->add_arg( spec => 'user|u=s', help => 'Username', default => 'www-data' ); $np->getopts; if($np->opts->user) { … } architects of the digital society www.capside.com
  • 17. Collect data Now you have to work architects of the digital society www.capside.com
  • 18. State calculation architects of the digital society www.capside.com
  • 19. Ranges  Most plugins suppose that • OK<WARNING<CRITICAL  But… what if… architects of the digital society www.capside.com
  • 20. Ranges Range definition Generate alert if x… 10 Is not between 0 and 10 10: Is not between 10 and infinity ~:10 Is not between –Inf and 10 10:20 Is not between 10 and 20 @10:20 Is between 10 and 20 $code= $np->check_threshold( check => $value, warning => $warning_threshold, critical => $critical_threshold ); $np->nagios_exit( $code, "Thresholdcheckfailed" ) if ($code!= OK); architects of the digital society www.capside.com
  • 21. Output status  $np->nagios_exit(CRITICAL, “Too many connections”);  $np->nagios_exit(OK, “Everything went fine”);  $np->nagios_exit(WARNING, “Too few connections”);  $np->nagios_exit(UNKNOWN, “Bad options”); architects of the digital society www.capside.com
  • 22. Performance Data $np->add_perfdata( label => "size", value => $value, uom => "kB", warning => $warning, critical => $critical ); UOM Unit of measurement Is for No unit specified Assume a number of things s,ms,us econds, miliseconds, nanoseconds % Percentage B,KB,MB,TB Bytes c A continuous counter architects of the digital society www.capside.com
  • 23. Success! Enjoy your shiny new plugin architects of the digital society www.capside.com
  • 24. Nagios::Plugin::DieNicely architects of the digital society www.capside.com
  • 25. Nagios::Plugin::DieNicely  Software fails, and sometimes you don’t control it architects of the digital society www.capside.com
  • 26. Nagios::Plugin::DieNicely  What happened? architects of the digital society www.capside.com
  • 27. Nagios::Plugin::DieNicely  What happened? • Output went to STDERR • Nagios doesn’t care • Exit code follows Perls rules • Nagios understands 0-3 architects of the digital society www.capside.com
  • 28. Nagios::Plugin::DieNicely  use Nagios::Plugin::DieNicely architects of the digital society www.capside.com
  • 29. Nagios::Plugin::WWW::Mechanize Nagios::Plugin + WWW::Mechanize architects of the digital society www.capside.com
  • 30. Nagios::Plugin::WWW::Mechanize Nagios::Plugin + WWW::Mechanize You where going to do it anyway! architects of the digital society www.capside.com
  • 31. Nagios::Plugin::WWW::Mechanize  Again... Just create an instance. Use it as a Nagios::Plugin object  Automatically tracks response time for you  $np->mech  $np->content  $np->get, $np->submit_form architects of the digital society www.capside.com
  • 32. Nagios::Plugin::WWW::Mechanize A couple of tricks • Gzipped content my $np = Nagios::Plugin::WWW::Mechanize->new( 'mech' => WWW::Mechanize::GZip->new(autocheck => 0) ); • Proxy my $proxy = $np->opts->proxy; if (defined $proxy){ $np->mech->proxy(['http', 'https'], $proxy); } architects of the digital society www.capside.com
  • 33. Nagios::Plugin::SNMP Nagios::Plugin + Net::SNMP architects of the digital society www.capside.com
  • 34. Nagios::Plugin::SNMP Again... Just create an instance. Use it as a Nagios::Plugin object Sets up a lot of arguments Does delta between values of counters architects of the digital society www.capside.com
  • 35. Any Questions? Thanks to: The Monitoring::Plugin module maintainers Icanhazcheezburger for the cats architects of the digital society www.capside.com

×