Fixing Perl strict errors in HAProxy monitoring plugin check_haproxy

Written by - 0 comments

Published on - Listed in HAProxy Perl Coding Monitoring Observability


To integrate HAProxy into a classic system monitoring, such as Nagios or Icinga, one very handy way is to use the monitoring plugin "check_haproxy.pl". 

I've been using this monitoring for the past 10 years and also contributed to it a while ago, adding performance data for the sessions and traffic per HAProxy backend. This allows to create nice graphs in Grafana for observability:

Bareword X not allowed while strict subs in use 

But lately I came across some Perl errors, when the plugin was executed on an Ubuntu 24.04 machine with Perl 5.38 and libmonitoring-plugin-perl 0.40-1:

ck@ubuntu-noble:~$ /usr/lib/nagios/plugins/check_haproxy.pl -u "http://mylovelyhaproxy.example.com:8099?stats;csv"
Bareword "CRITICAL" not allowed while "strict subs" in use at /usr/lib/nagios/plugins/check_haproxy.pl line 184.
Bareword "CRITICAL" not allowed while "strict subs" in use at /usr/lib/nagios/plugins/check_haproxy.pl line 187.
Bareword "CRITICAL" not allowed while "strict subs" in use at /usr/lib/nagios/plugins/check_haproxy.pl line 200.
Bareword "CRITICAL" not allowed while "strict subs" in use at /usr/lib/nagios/plugins/check_haproxy.pl line 209.
Bareword "OK" not allowed while "strict subs" in use at /usr/lib/nagios/plugins/check_haproxy.pl line 229.
Bareword "OK" not allowed while "strict subs" in use at /usr/lib/nagios/plugins/check_haproxy.pl line 241.
Bareword "UNKNOWN" not allowed while "strict subs" in use at /usr/lib/nagios/plugins/check_haproxy.pl line 254.
Bareword "CRITICAL" not allowed while "strict subs" in use at /usr/lib/nagios/plugins/check_haproxy.pl line 300.
Bareword "WARNING" not allowed while "strict subs" in use at /usr/lib/nagios/plugins/check_haproxy.pl line 303.
Bareword "CRITICAL" not allowed while "strict subs" in use at /usr/lib/nagios/plugins/check_haproxy.pl line 306.
/usr/lib/nagios/plugins/check_haproxy.pl has too many errors. 

Missing string "doublequotes"

The Perl errors are very helpful here; they precisely show the string (BAREWORD) causing the problem in which line. Example in the mentioned line 184:

$np->add_message(CRITICAL, _gt("HTTP error: ").$err );

By simply putting the message (CRITICAL) into a valid string fixes the strict subs error:

$np->add_message("CRITICAL", _gt("HTTP error: ").$err );

The plugin is working nicely again:

ck@ubuntu-noble:~$ /usr/lib/nagios/plugins/check_haproxy.pl -u "http://mylovelyhaproxy.example.com:8099?stats;csv"
HAPROXY OK -  myapp-out (Active: 1/1) | t=0.047756s;2;10;0; sess_myapp-out=1;;;0;26212 bytes_in_myapp-out=72341102B;;;0; bytes_out_myapp-out=1188288893B;;;0;

The fixed version is check_haproxy.pl v1.2 and can be found here


Add a comment

Show form to leave a comment

Comments (newest first)

No comments yet.

RSS feed

Blog Tags:

  AWS   Android   Ansible   Apache   Apple   Atlassian   BSD   Backup   Bash   Bluecoat   CMS   Chef   Cloud   Coding   Consul   Containers   CouchDB   DB   DNS   Databases   Docker   ELK   Elasticsearch   Filebeat   FreeBSD   Galera   Git   GlusterFS   Grafana   Graphics   HAProxy   HTML   Hacks   Hardware   Icinga   Influx   Internet   Java   KVM   Kibana   Kodi   Kubernetes   LVM   LXC   Linux   Logstash   Mac   Macintosh   Mail   MariaDB   Minio   MongoDB   Monitoring   Multimedia   MySQL   NFS   Nagios   Network   Nginx   OSSEC   OTRS   Observability   Office   OpenSearch   PHP   Perl   Personal   PostgreSQL   PowerDNS   Proxmox   Proxy   Python   Rancher   Rant   Redis   Roundcube   SSL   Samba   Seafile   Security   Shell   SmartOS   Solaris   Surveillance   Systemd   TLS   Tomcat   Ubuntu   Unix   VMWare   VMware   Varnish   Virtualization   Windows   Wireless   Wordpress   Wyse   ZFS   Zoneminder    Linux