SlideShare a Scribd company logo
Writing Custom Nagios Plugins
Janice Singh
Nagios Administrator
Introduction
• About the Presentation
– audience
• anyone with basic nagios knowledge
• anyone with basic scripting/coding knowledge
– what a plugin is
– how to write one
– troubleshooting
• About Me
– work at NAS (NASA Advanced Supercomputing)
– used Nagios for 5 years
• started at Nagios 2.10
• written/maintain 25+ plugins
janice.s.singh@nasa.gov 2
NASA Advanced Supercomputing
• Pleiades
– 11,312-node SGI ICE supercluster
– 184,800 cores
• Endeavour
– 2 node SGI shared memory system
– 1,536 cores
• Merope
– 1,152 node SGI cluster
– 13,824 cores
• Hyperwall visualization cluster
– 128-screen LCD wall arranged in 8x16 configuration
– measures 23-ft. wide by 10-ft. high
– 2,560 processor cores
• Tape Storage - pDMF cluster
– 4 front ends
– 47 PB of unique file data stored
Ref: http://www.nas.nasa.gov/hecc/
janice.s.singh@nasa.gov 3
Nagios at NASA Advanced Supercomputing
• one main Nagios server
• systems behind firewall send data by nrdp
• some clusters behind firewall
– one cluster uses nrpe for gathering data
– other clusters use ssh
• Post processor prepares visualization (HUD) data
– separate daemon
– Nagios APIs provide configuration and status data
– provides file read by HUD
– general architecture adaptable for other uses
janice.s.singh@nasa.gov 4
HUD
janice.s.singh@nasa.gov 5
Plugins – Nagios extensions
• Built-in plugins
– Aren’t truly built-in, but they come standard when you install
nagios-plugins
• check_disk
• check_ping
• Custom plugins
– Let you test anything
– The sky’s the limit - if you can code it, you can test it
janice.s.singh@nasa.gov 6
How to Use Plugins
Nagios configuration to define a service that will use the plugin
check_mydaemon.pl:
define service {
host linuxserver2
service_description Check MyDaemon
check_command check_mydaemon!5!10
}
define command {
command_name check_mydaemon
command_line check_mydaemon.pl –w $ARG1$ –c $ARG2$
}
janice.s.singh@nasa.gov 7
Reasons to write your own plugin
• There isn’t a plugin out there that tests what you want
• You need to test it differently
janice.s.singh@nasa.gov 8
Guidelines
• Any Language you want
• There is only one rule: it must return a nagios-accepted value
ok (green) 0
warning (yellow) 1
critical (red) 2
unknown (orange) 3
janice.s.singh@nasa.gov 9
Plugin Psuedocode
• General outline of what a plugin needs to do:
– initialize object (if object oriented code)
– read in the arguments
– set variables
– do the test
– return results
• This is just a suggestion
janice.s.singh@nasa.gov 10
For Perl: Nagios::Plugin
# Instantiate Nagios::Plugin object (the 'usage' parameter is mandatory)
my $p = Nagios::Plugin->new(
usage => ”usage_string",
version => $version_number,
blurb => ‘brief info on plugin',
extra => ‘extended info on plugin’
);
janice.s.singh@nasa.gov 11
For Perl: Nagios::Plugin (cont).
# adding an argument ex: check_mydaemon.pl -w
# define help string neatly – use below instead of qq
my $hlp_strg = ‘-w, --warning=INTEGER:INTEGERn’ .
‘ If omitted, warning is generated.’;
$p->add_arg(
spec => 'warning|w=s’,
help => $hlp_strg
required => 1,
default => 10,
);
#accessing the argument
$p->getopts;
$p->opts->warning
janice.s.singh@nasa.gov 12
For Perl: Nagios::Plugin (cont).
# finishing the script:
$p->nagios_exit(
return_code => $p->check_threshold($result),
message => " info on what $result means"
);
# if you are not using check_threshold use text for return code:
return_code => ‘OK|WARNING|CRITICAL|UNKNOWN’
janice.s.singh@nasa.gov 13
For Perl: Nagios::Plugin (cont).
• When you’ve done your code and have $result to compare to
the thresholds:
– $return_code = $p->check_threshold($result)
– follows nagios convention of min:max
• check_mydaemon.pl –w 5 will warn on > 5
• check_mydaemon.pl –w :5 will warn on > 5
• check_mydaemon.pl –w 5: will warn on < 5
• check_mydaemon.pl –w 5:7 will warn on <5 or >7 (outside
the range)
• check_mydaemon.pl –w @5:7 will warn on >=5 or <=7
(within the range)
• if you overlap critical and warning, critical has precedent
janice.s.singh@nasa.gov 14
Putting it All Together –simplified
use Nagios::Plugin ;
my $p = Nagios::Plugin->new(
usage => "Usage: %s [ -f|--filesystem = <filesystem name> ]",
version => $VERSION,
blurb => 'This will test to see if the specified filesystem is mounted
or not. It will output OK if it is mounted, CRITICAL if it not.',
extra => "
-f, --filesystem is required.
"
);
janice.s.singh@nasa.gov 15
Putting it All Together –simplified (cont).
$p->add_arg(
spec => 'filesystem|f=s',
help =>
qq{-f, --filesystem=STRING
The filesystem to check for.},
required => 1,
);
$p->getopts;
my $filesystem = $p->opts->filesystem;
janice.s.singh@nasa.gov 16
Putting it All Together –simplified (cont).
my $result = `mount | grep $filesystem`;
if ($result ne "") {
$p->nagios_exit(
return_code => OK,
message => "$filesystem is mounted"
);
} else {
$p->nagios_exit(
return_code => UNKNOWN,
message => "$filesystem is not mounted"
);
}
./check_mounted.pl -f nobackupp8
MOUNTED OK - nobackupp8 is mounted
janice.s.singh@nasa.gov 17
Timeouts
• Many times you need to make sure a plugin ends within a
specified time
– in nagios.cfg:
service_check_timeout=60
– in this case you’d want to specify a 60 second timeout
• with Nagios::Plugin
– ./mydaemon.pl –t 60
– alarm($p->opts->timeout);
janice.s.singh@nasa.gov 18
Overcoming issues
• Test needs elevated privilege
• nagios can be run as root but is not secure
– run the test as root via cronjob; write info to a flat file
– use nagios plugin to read and process the file
• Output of the test was too big
– the resulting nrdp command hit a kernel limit
– use scp to get the output to the main nagios server
ex: scp command_output nagios_server:
– use plugin on the main server to process it
janice.s.singh@nasa.gov 19
Nagios perfdata
• Nagios is designed to allow plugins to return optional
performance data in addition to normal status data
– in nagios.cfg enable the process_performance_data option.
– Nagios collects this information to be displayed on the GUI
– in the format “|key1=value1,key2=value2,…,keyN=valueN”
– this can be anything that has a numerical value
janice.s.singh@nasa.gov 20
Troubleshooting
• The Nagios display says: return code XXX is out of bounds
– your script returns anything other than 0,1,2,3
– otherwise it is a nagios error.
• Google is your friend
– ex: 13 usually means a permission error
– sometimes all it tells you is “something went wrong”
– these disappeared at our site when we switched to
Nagios::Plugin
• try running the plugin from the command line
– verify who you are running as
– verify the arguments passed in
janice.s.singh@nasa.gov 21
Troubleshooting (cont).
• Timing is everything!
– files can get overwritten
• by cron jobs
• by multiple nagios processes
– launching too many processes
• if perfdata is enabled, the perfdata log is the most useful
janice.s.singh@nasa.gov 22
Questions
• Any Questions
janice.s.singh@nasa.gov 23

More Related Content

PDF
Trevor McDonald - Nagios XI Under The Hood
PDF
Jesse Olson - Nagios Log Server Architecture Overview
PDF
Mike Guthrie - Revamping Your 10 Year Old Nagios Installation
ODP
Nagios Conference 2012 - Mike Weber - Failover
PDF
Nagios Conference 2013 - John Sellens - Monitoring Remote Locations with Nagios
ODP
Nagios Conference 2013 - Eric Stanley - Whats New Core 4
PDF
Dave Williams - Nagios Log Server - Practical Experience
Trevor McDonald - Nagios XI Under The Hood
Jesse Olson - Nagios Log Server Architecture Overview
Mike Guthrie - Revamping Your 10 Year Old Nagios Installation
Nagios Conference 2012 - Mike Weber - Failover
Nagios Conference 2013 - John Sellens - Monitoring Remote Locations with Nagios
Nagios Conference 2013 - Eric Stanley - Whats New Core 4
Dave Williams - Nagios Log Server - Practical Experience

What's hot (20)

ODP
Nagios Conference 2014 - Eric Mislivec - Getting Started With Nagios Core
ODP
Nagios Conference 2014 - Leland Lammert - Distributed Heirarchical Nagios
PDF
Lee Myers - What To Do When Nagios Notification Don't Meet Your Needs.
PPTX
Nagios Conference 2014 - Mike Merideth - The Art and Zen of Managing Nagios w...
PPTX
Nagios Conference 2014 - James Clark - Nagios Cool Tips and Tricks
PPT
Nagios Conference 2014 - Janice Singh - Real World Uses for Nagios APIs
KEY
Nginx - Tips and Tricks.
PDF
How to monitor NGINX
PPTX
NGINX: Basics & Best Practices - EMEA Broadcast
PPTX
Nagios Conference 2014 - Luis Contreras - Monitoring SAP System with Nagios Core
PPTX
Nagios Conference 2014 - Jim Prins - Passive Monitoring with Nagios
PDF
Extending functionality in nginx, with modules!
PPTX
PPT
Nginx internals
PPTX
5 things you didn't know nginx could do
PPTX
Learn nginx in 90mins
PPTX
Maximizing PHP Performance with NGINX
PDF
Nagios Conference 2014 - Jack Chu - How to Think With Nagios to Solve Monitor...
PDF
What's New in NGINX Plus R12?
PDF
Nginx Essential
Nagios Conference 2014 - Eric Mislivec - Getting Started With Nagios Core
Nagios Conference 2014 - Leland Lammert - Distributed Heirarchical Nagios
Lee Myers - What To Do When Nagios Notification Don't Meet Your Needs.
Nagios Conference 2014 - Mike Merideth - The Art and Zen of Managing Nagios w...
Nagios Conference 2014 - James Clark - Nagios Cool Tips and Tricks
Nagios Conference 2014 - Janice Singh - Real World Uses for Nagios APIs
Nginx - Tips and Tricks.
How to monitor NGINX
NGINX: Basics & Best Practices - EMEA Broadcast
Nagios Conference 2014 - Luis Contreras - Monitoring SAP System with Nagios Core
Nagios Conference 2014 - Jim Prins - Passive Monitoring with Nagios
Extending functionality in nginx, with modules!
Nginx internals
5 things you didn't know nginx could do
Learn nginx in 90mins
Maximizing PHP Performance with NGINX
Nagios Conference 2014 - Jack Chu - How to Think With Nagios to Solve Monitor...
What's New in NGINX Plus R12?
Nginx Essential
Ad

Viewers also liked (20)

PPTX
Nagios XI Best Practices
PDF
Sean Falzon - Nagios - Resilient Notifications
PDF
Marcus Rochelle - Landis+Gyr - Monitoring with Nagios Enterprise Edition
PDF
Writing nagios plugins in perl
PPTX
Nagios Conference 2012 - Nathan Vonnahme - Writing Custom Nagios Plugins in Perl
PPTX
Nagios Conference 2011 - Nathan Vonnahme - Writing Custom Nagios Plugins In Perl
PDF
Jenkins
PDF
Nagios, Getting Started.
PPT
Nagios Conference 2014 - Konstantin Benz - Monitoring Openstack The Relations...
PPTX
Nagios Conference 2014 - Dorance Martinez Cortes - Customizing Nagios
ODP
Nagios Conference 2014 - Mike Weber - Nagios Rapid Deployment Options
PPTX
Service Support Process PPT
PDF
Bryan Heden - Agile Networks - Using Nagios XI as the platform for Monitoring...
KEY
Using Nagios with Chef
ODP
Writing Nagios Plugins in Python
PDF
Matt Bruzek - Monitoring Your Public Cloud With Nagios
PDF
Eric Loyd - Fractal Nagios
PDF
Thomas Schmainda - Tracking Boeing Satellites With Nagios - Nagios World Conf...
PPTX
Itism.v20160321.2eng public
PPTX
Nagios World Conference 2015 - Scott Wilkerson Opening
Nagios XI Best Practices
Sean Falzon - Nagios - Resilient Notifications
Marcus Rochelle - Landis+Gyr - Monitoring with Nagios Enterprise Edition
Writing nagios plugins in perl
Nagios Conference 2012 - Nathan Vonnahme - Writing Custom Nagios Plugins in Perl
Nagios Conference 2011 - Nathan Vonnahme - Writing Custom Nagios Plugins In Perl
Jenkins
Nagios, Getting Started.
Nagios Conference 2014 - Konstantin Benz - Monitoring Openstack The Relations...
Nagios Conference 2014 - Dorance Martinez Cortes - Customizing Nagios
Nagios Conference 2014 - Mike Weber - Nagios Rapid Deployment Options
Service Support Process PPT
Bryan Heden - Agile Networks - Using Nagios XI as the platform for Monitoring...
Using Nagios with Chef
Writing Nagios Plugins in Python
Matt Bruzek - Monitoring Your Public Cloud With Nagios
Eric Loyd - Fractal Nagios
Thomas Schmainda - Tracking Boeing Satellites With Nagios - Nagios World Conf...
Itism.v20160321.2eng public
Nagios World Conference 2015 - Scott Wilkerson Opening
Ad

Similar to Janice Singh - Writing Custom Nagios Plugins (20)

PPTX
Nagios Conference 2014 - Rob Hassing - How To Maintain Over 20 Monitoring App...
ODP
Monitoring at/with SUSE 2015
PDF
The Accidental DBA
PDF
MySQL Utilities -- PyTexas 2015
PPT
Nagios Conference 2013 - Janice Singh - Visualization of Monitoring Data at t...
PPTX
Nagios Conference 2014 - Frank Pantaleo - Nagios Monitoring of Netezza Databases
PDF
New Jersey Red Hat Users Group Presentation: Provisioning anywhere
PDF
Automating Complex Setups with Puppet
PDF
Storage managment using nagios
PDF
Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...
PPTX
Nagios Conference 2011 - Nate Broderick - Nagios XI Large Implementation Tips...
PDF
Automating complex infrastructures with Puppet
PDF
#OktoCampus - Workshop : An introduction to Ansible
PPTX
A Year in Google - Percona Live Europe 2018
PDF
Ansible is the simplest way to automate. MoldCamp, 2015
PDF
Replication using PostgreSQL Replicator
PDF
Go replicator
PDF
apidays LIVE New York - Navigating the Sea of Javascript Tools to Discover Sc...
PPTX
NGINX Installation and Tuning
DOC
X64服务器 lnmp服务器部署标准 new
Nagios Conference 2014 - Rob Hassing - How To Maintain Over 20 Monitoring App...
Monitoring at/with SUSE 2015
The Accidental DBA
MySQL Utilities -- PyTexas 2015
Nagios Conference 2013 - Janice Singh - Visualization of Monitoring Data at t...
Nagios Conference 2014 - Frank Pantaleo - Nagios Monitoring of Netezza Databases
New Jersey Red Hat Users Group Presentation: Provisioning anywhere
Automating Complex Setups with Puppet
Storage managment using nagios
Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...
Nagios Conference 2011 - Nate Broderick - Nagios XI Large Implementation Tips...
Automating complex infrastructures with Puppet
#OktoCampus - Workshop : An introduction to Ansible
A Year in Google - Percona Live Europe 2018
Ansible is the simplest way to automate. MoldCamp, 2015
Replication using PostgreSQL Replicator
Go replicator
apidays LIVE New York - Navigating the Sea of Javascript Tools to Discover Sc...
NGINX Installation and Tuning
X64服务器 lnmp服务器部署标准 new

More from Nagios (14)

PDF
Mike Weber - Nagios and Group Deployment of Service Checks
PDF
Marcelo Perazolo, Lead Software Architect, IBM Corporation - Monitoring a Pow...
PDF
Nrpe - Nagios Remote Plugin Executor. NRPE plugin for Nagios Core
PDF
Nagios Log Server - Features
PDF
Nagios Network Analyzer - Features
ODP
Nagios Conference 2014 - Trevor McDonald - Monitoring The Physical World With...
ODP
Nagios Conference 2014 - Andy Brist - Nagios XI Failover and HA Solutions
ODP
Nagios Conference 2014 - Shamas Demoret - An Overview of Nagios Solutions
ODP
Nagios Conference 2014 - Shamas Demoret - Getting Started With Nagios XI
PPTX
Nagios Conference 2014 - Abbas Haider Ali - Proactive Alerting and Intelligen...
PPTX
Nagios Conference 2014 - Sam Lansing - Utilizing Data Visualizations in Syste...
PPTX
Nagios Conference 2014 - Sam Lansing - Advanced Features of Nagios XI
PPTX
Nagios Conference 2014 - Paloma Galan - Monitoring Financial Protocols With N...
PPTX
Nagios Conference 2014 - Scott Wilkerson - Getting Started with Nagios Networ...
Mike Weber - Nagios and Group Deployment of Service Checks
Marcelo Perazolo, Lead Software Architect, IBM Corporation - Monitoring a Pow...
Nrpe - Nagios Remote Plugin Executor. NRPE plugin for Nagios Core
Nagios Log Server - Features
Nagios Network Analyzer - Features
Nagios Conference 2014 - Trevor McDonald - Monitoring The Physical World With...
Nagios Conference 2014 - Andy Brist - Nagios XI Failover and HA Solutions
Nagios Conference 2014 - Shamas Demoret - An Overview of Nagios Solutions
Nagios Conference 2014 - Shamas Demoret - Getting Started With Nagios XI
Nagios Conference 2014 - Abbas Haider Ali - Proactive Alerting and Intelligen...
Nagios Conference 2014 - Sam Lansing - Utilizing Data Visualizations in Syste...
Nagios Conference 2014 - Sam Lansing - Advanced Features of Nagios XI
Nagios Conference 2014 - Paloma Galan - Monitoring Financial Protocols With N...
Nagios Conference 2014 - Scott Wilkerson - Getting Started with Nagios Networ...

Recently uploaded (20)

PPTX
The spiral of silence is a theory in communication and political science that...
PPTX
Non-Verbal-Communication .mh.pdf_110245_compressed.pptx
PPTX
worship songs, in any order, compilation
PPTX
_ISO_Presentation_ISO 9001 and 45001.pptx
PPTX
Tablets And Capsule Preformulation Of Paracetamol
PPTX
The Effect of Human Resource Management Practice on Organizational Performanc...
PPTX
BIOLOGY TISSUE PPT CLASS 9 PROJECT PUBLIC
PPTX
Relationship Management Presentation In Banking.pptx
PPTX
Understanding-Communication-Berlos-S-M-C-R-Model.pptx
PPTX
Tour Presentation Educational Activity.pptx
PPTX
Emphasizing It's Not The End 08 06 2025.pptx
PPTX
An Unlikely Response 08 10 2025.pptx
PPTX
2025-08-10 Joseph 02 (shared slides).pptx
PDF
Nykaa-Strategy-Case-Fixing-Retention-UX-and-D2C-Engagement (1).pdf
PPTX
Learning-Plan-5-Policies-and-Practices.pptx
PPTX
INTERNATIONAL LABOUR ORAGNISATION PPT ON SOCIAL SCIENCE
DOCX
ENGLISH PROJECT FOR BINOD BIHARI MAHTO KOYLANCHAL UNIVERSITY
PPTX
Self management and self evaluation presentation
PPTX
Primary and secondary sources, and history
PPTX
fundraisepro pitch deck elegant and modern
The spiral of silence is a theory in communication and political science that...
Non-Verbal-Communication .mh.pdf_110245_compressed.pptx
worship songs, in any order, compilation
_ISO_Presentation_ISO 9001 and 45001.pptx
Tablets And Capsule Preformulation Of Paracetamol
The Effect of Human Resource Management Practice on Organizational Performanc...
BIOLOGY TISSUE PPT CLASS 9 PROJECT PUBLIC
Relationship Management Presentation In Banking.pptx
Understanding-Communication-Berlos-S-M-C-R-Model.pptx
Tour Presentation Educational Activity.pptx
Emphasizing It's Not The End 08 06 2025.pptx
An Unlikely Response 08 10 2025.pptx
2025-08-10 Joseph 02 (shared slides).pptx
Nykaa-Strategy-Case-Fixing-Retention-UX-and-D2C-Engagement (1).pdf
Learning-Plan-5-Policies-and-Practices.pptx
INTERNATIONAL LABOUR ORAGNISATION PPT ON SOCIAL SCIENCE
ENGLISH PROJECT FOR BINOD BIHARI MAHTO KOYLANCHAL UNIVERSITY
Self management and self evaluation presentation
Primary and secondary sources, and history
fundraisepro pitch deck elegant and modern

Janice Singh - Writing Custom Nagios Plugins

  • 1. Writing Custom Nagios Plugins Janice Singh Nagios Administrator
  • 2. Introduction • About the Presentation – audience • anyone with basic nagios knowledge • anyone with basic scripting/coding knowledge – what a plugin is – how to write one – troubleshooting • About Me – work at NAS (NASA Advanced Supercomputing) – used Nagios for 5 years • started at Nagios 2.10 • written/maintain 25+ plugins janice.s.singh@nasa.gov 2
  • 3. NASA Advanced Supercomputing • Pleiades – 11,312-node SGI ICE supercluster – 184,800 cores • Endeavour – 2 node SGI shared memory system – 1,536 cores • Merope – 1,152 node SGI cluster – 13,824 cores • Hyperwall visualization cluster – 128-screen LCD wall arranged in 8x16 configuration – measures 23-ft. wide by 10-ft. high – 2,560 processor cores • Tape Storage - pDMF cluster – 4 front ends – 47 PB of unique file data stored Ref: http://www.nas.nasa.gov/hecc/ janice.s.singh@nasa.gov 3
  • 4. Nagios at NASA Advanced Supercomputing • one main Nagios server • systems behind firewall send data by nrdp • some clusters behind firewall – one cluster uses nrpe for gathering data – other clusters use ssh • Post processor prepares visualization (HUD) data – separate daemon – Nagios APIs provide configuration and status data – provides file read by HUD – general architecture adaptable for other uses janice.s.singh@nasa.gov 4
  • 6. Plugins – Nagios extensions • Built-in plugins – Aren’t truly built-in, but they come standard when you install nagios-plugins • check_disk • check_ping • Custom plugins – Let you test anything – The sky’s the limit - if you can code it, you can test it janice.s.singh@nasa.gov 6
  • 7. How to Use Plugins Nagios configuration to define a service that will use the plugin check_mydaemon.pl: define service { host linuxserver2 service_description Check MyDaemon check_command check_mydaemon!5!10 } define command { command_name check_mydaemon command_line check_mydaemon.pl –w $ARG1$ –c $ARG2$ } janice.s.singh@nasa.gov 7
  • 8. Reasons to write your own plugin • There isn’t a plugin out there that tests what you want • You need to test it differently janice.s.singh@nasa.gov 8
  • 9. Guidelines • Any Language you want • There is only one rule: it must return a nagios-accepted value ok (green) 0 warning (yellow) 1 critical (red) 2 unknown (orange) 3 janice.s.singh@nasa.gov 9
  • 10. Plugin Psuedocode • General outline of what a plugin needs to do: – initialize object (if object oriented code) – read in the arguments – set variables – do the test – return results • This is just a suggestion janice.s.singh@nasa.gov 10
  • 11. For Perl: Nagios::Plugin # Instantiate Nagios::Plugin object (the 'usage' parameter is mandatory) my $p = Nagios::Plugin->new( usage => ”usage_string", version => $version_number, blurb => ‘brief info on plugin', extra => ‘extended info on plugin’ ); janice.s.singh@nasa.gov 11
  • 12. For Perl: Nagios::Plugin (cont). # adding an argument ex: check_mydaemon.pl -w # define help string neatly – use below instead of qq my $hlp_strg = ‘-w, --warning=INTEGER:INTEGERn’ . ‘ If omitted, warning is generated.’; $p->add_arg( spec => 'warning|w=s’, help => $hlp_strg required => 1, default => 10, ); #accessing the argument $p->getopts; $p->opts->warning janice.s.singh@nasa.gov 12
  • 13. For Perl: Nagios::Plugin (cont). # finishing the script: $p->nagios_exit( return_code => $p->check_threshold($result), message => " info on what $result means" ); # if you are not using check_threshold use text for return code: return_code => ‘OK|WARNING|CRITICAL|UNKNOWN’ janice.s.singh@nasa.gov 13
  • 14. For Perl: Nagios::Plugin (cont). • When you’ve done your code and have $result to compare to the thresholds: – $return_code = $p->check_threshold($result) – follows nagios convention of min:max • check_mydaemon.pl –w 5 will warn on > 5 • check_mydaemon.pl –w :5 will warn on > 5 • check_mydaemon.pl –w 5: will warn on < 5 • check_mydaemon.pl –w 5:7 will warn on <5 or >7 (outside the range) • check_mydaemon.pl –w @5:7 will warn on >=5 or <=7 (within the range) • if you overlap critical and warning, critical has precedent janice.s.singh@nasa.gov 14
  • 15. Putting it All Together –simplified use Nagios::Plugin ; my $p = Nagios::Plugin->new( usage => "Usage: %s [ -f|--filesystem = <filesystem name> ]", version => $VERSION, blurb => 'This will test to see if the specified filesystem is mounted or not. It will output OK if it is mounted, CRITICAL if it not.', extra => " -f, --filesystem is required. " ); janice.s.singh@nasa.gov 15
  • 16. Putting it All Together –simplified (cont). $p->add_arg( spec => 'filesystem|f=s', help => qq{-f, --filesystem=STRING The filesystem to check for.}, required => 1, ); $p->getopts; my $filesystem = $p->opts->filesystem; janice.s.singh@nasa.gov 16
  • 17. Putting it All Together –simplified (cont). my $result = `mount | grep $filesystem`; if ($result ne "") { $p->nagios_exit( return_code => OK, message => "$filesystem is mounted" ); } else { $p->nagios_exit( return_code => UNKNOWN, message => "$filesystem is not mounted" ); } ./check_mounted.pl -f nobackupp8 MOUNTED OK - nobackupp8 is mounted janice.s.singh@nasa.gov 17
  • 18. Timeouts • Many times you need to make sure a plugin ends within a specified time – in nagios.cfg: service_check_timeout=60 – in this case you’d want to specify a 60 second timeout • with Nagios::Plugin – ./mydaemon.pl –t 60 – alarm($p->opts->timeout); janice.s.singh@nasa.gov 18
  • 19. Overcoming issues • Test needs elevated privilege • nagios can be run as root but is not secure – run the test as root via cronjob; write info to a flat file – use nagios plugin to read and process the file • Output of the test was too big – the resulting nrdp command hit a kernel limit – use scp to get the output to the main nagios server ex: scp command_output nagios_server: – use plugin on the main server to process it janice.s.singh@nasa.gov 19
  • 20. Nagios perfdata • Nagios is designed to allow plugins to return optional performance data in addition to normal status data – in nagios.cfg enable the process_performance_data option. – Nagios collects this information to be displayed on the GUI – in the format “|key1=value1,key2=value2,…,keyN=valueN” – this can be anything that has a numerical value janice.s.singh@nasa.gov 20
  • 21. Troubleshooting • The Nagios display says: return code XXX is out of bounds – your script returns anything other than 0,1,2,3 – otherwise it is a nagios error. • Google is your friend – ex: 13 usually means a permission error – sometimes all it tells you is “something went wrong” – these disappeared at our site when we switched to Nagios::Plugin • try running the plugin from the command line – verify who you are running as – verify the arguments passed in janice.s.singh@nasa.gov 21
  • 22. Troubleshooting (cont). • Timing is everything! – files can get overwritten • by cron jobs • by multiple nagios processes – launching too many processes • if perfdata is enabled, the perfdata log is the most useful janice.s.singh@nasa.gov 22