{"id":4468,"date":"2019-10-20T13:35:09","date_gmt":"2019-10-20T10:35:09","guid":{"rendered":"https:\/\/kifarunix.com\/?p=4468"},"modified":"2024-03-12T22:06:00","modified_gmt":"2024-03-12T19:06:00","slug":"monitor-ssl-tls-certificates-expiry-with-nagios","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/monitor-ssl-tls-certificates-expiry-with-nagios\/","title":{"rendered":"Monitor SSL\/TLS Certificates Expiry with Nagios"},"content":{"rendered":"\n
Well, assuming you understand the implications of the expired SSL\/TLS certificates,<\/a> let us go through how to monitor SSL\/TLS Certificates Expiry with Nagios. Nagios provides SSL Certificate monitoring and alerting when SSL certificates expiration date draws closer using the Nagios Plugins.<\/p>\n\n\n\n Before you can proceed, install and setup Nagios server. Follow the links below to setup Nagios server on your desired system.<\/p>\n\n\n\n Install Nagios Server on CentOS 8<\/a><\/p>\n\n\n\n Install Nagios Core on Debian 10 Buster<\/a><\/p>\n\n\n\n Once your Nagios server is up and ready proceed to configure it to monitor your web servers SSL\/TLS certificates expiry.<\/p>\n\n\n\n Reporting on certificate expiration times is the main focus of this guide.<\/p>\n\n\n\n Nagios plugins provide the check_http plugin script. Below is a sample guide on how to install Nagios plugins on the Nagios server.<\/p>\n\n\n\n Install Nagios Plugins From Source RHEL\/CentOS\/Oracle Linux<\/a><\/p>\n\n\n\n Next, you need to add the host whose SSL\/TLS certificates is to be monitored to Nagios Server. See a sample guide below;<\/p>\n\n\n\n Add Hosts to Nagios Server For Monitoring<\/a><\/p>\n\n\n\n Create a command object definition that defines how to use the check_http command to monitor the SSL\/TLS certificates.<\/p>\n\n\n\n If you compiled Nagios from the source, then create the command definition configuration on Be sure to replace PATHS accordingly.<\/strong><\/p>\n\n\n\n After creating the command object definition to check SSL certificate, proceed to define a service that calls the If you need to monitor other ports like SMTPS, POPS, IMAPS, you can add such service definitions to your Service Object definition configuration file.<\/p>\n\n\n\n It is a wise idea to check Nagios configuration of syntax errors everytime you make changes.<\/p>\n\n\n\n If there are no errors, restart Nagios service.<\/p>\n\n\n\n Verify the SSL checks from command line;<\/p>\n\n\n\n You can also Navigate to Nagios web interface to verify the SSL checks.<\/p>\n\n\n\n There you go. You will now be notified when you SSL\/TLS certificate expiry date is 10 days or below.<\/p>\n\n\n\n Want to be notified via Email? Follow the link below to learn how to configure Nagios email notification using Gmail.<\/p>\n\n\n\nMonitoring SSL\/TLS Certificates Expiry with Nagios<\/h2>\n\n\n\n
check_http<\/a><\/strong><\/code> Nagios plugin is used to test the HTTP service on the specified host. It can test normal (http) and secure (https) servers, follow redirects, search for strings and regular expressions, check connection times, and report on certificate expiration times.<\/p>\n\n\n\n
Install Nagios Plugins<\/h3>\n\n\n\n
Add the Host to Nagios Server<\/h3>\n\n\n\n
Create Check_HTTP Command Object Definition<\/h3>\n\n\n\n
\/usr\/local\/nagios\/etc\/objects<\/code>. You can also use your own custom sub-directory, like
\/usr\/local\/nagios\/etc\/objects\/kifarunix-demo<\/code>, for our case.<\/p>\n\n\n\n
vim \/usr\/local\/nagios\/etc\/objects\/kifarunix-demo\/commands.cfg<\/code><\/pre>\n\n\n\n
# Check SSL\/TLS Certificate Expiry Command Definition<\/strong>\ndefine command{\n command_name check_certs\n command_line \/usr\/local\/nagios\/libexec\/check_http -S -I $HOSTADDRESS$ -p $ARG1$ -C $ARG2$\n}<\/code><\/pre>\n\n\n\n
\n
check_certs<\/code> and will be called in the service definition using this name.<\/li>\n\n\n\n
\/usr\/local\/nagios\/libexec\/check_http<\/code> specifies the location of the Nagios script.<\/li>\n\n\n\n
-S<\/strong><\/code> instructs the check_http plugin to check the SSL port which defaults to 443.<\/li>\n\n\n\n
-I<\/strong><\/code> option specifies IP address or name of the host. You can as well use the
-H<\/code> option for hostname argument for servers using host headers (virtual host).<\/li>\n\n\n\n
-p<\/code><\/strong> specifies port number to check. Useful if you want to check SSL for other ports ike SMTPS, IMAPS, POP3S<\/li>\n\n\n\n
-C<\/code><\/strong> specifies the minimum number of days a certificate has to be valid.<\/li>\n<\/ul>\n\n\n\n
Create Check_HTTP Service Object Definition<\/h3>\n\n\n\n
check_certs<\/code> object defined above.<\/p>\n\n\n\n
vim \/usr\/local\/nagios\/etc\/objects\/kifarunix-demo\/services.cfg<\/code><\/pre>\n\n\n\n
define service{\n use kifarunix-demo-service\n host_name web01.kifarunix-demo.com \n service_description HTTPS SSL Certificate\n check_command check_certs!443!10\n }<\/code><\/pre>\n\n\n\n
\n
use<\/strong><\/code> statement defines the service template to use.<\/li>\n\n\n\n
host_name<\/code><\/strong> specifies the host to check the SSL expiry against.<\/li>\n\n\n\n
service_description<\/code><\/strong> is the description of the service name.<\/li>\n\n\n\n
check_command<\/code><\/strong> specifies the name of the command that should be used to check SSL certificate as defined on the command definition above.<\/li>\n\n\n\n
-p $ARG1$<\/code><\/strong>.<\/li>\n\n\n\n
!10<\/code><\/strong> specifies the value of the
-C $ARG2$<\/strong><\/code> in the command definition. Hence, you will receive notification 10 days to certificate expiry.<\/li>\n<\/ul>\n\n\n\n
define service{\n use kifarunix-demo-service\n host_name mail.kifarunix-demo.com \n service_description SMTP SSL Certificate\n check_command check_certs!465!10\n }\ndefine service{\n use kifarunix-demo-service\n host_name mail.kifarunix-demo.com \n service_description SMTP TLS Certificate\n check_command check_certs!587!10\n }\ndefine service{\n use kifarunix-demo-service\n host_name mail.kifarunix-demo.com \n service_description IMAPS Certificate\n check_command check_certs!993!10\n }\ndefine service{\n use kifarunix-demo-service\n host_name mail.kifarunix-demo.com \n service_description POP3 SSL Certificate\n check_command check_certs!995!10\n }<\/code><\/pre>\n\n\n\n
Verify Nagios Configuration<\/h3>\n\n\n\n
\/usr\/local\/nagios\/bin\/nagios -v \/usr\/local\/nagios\/etc\/nagios.cfg<\/code><\/pre>\n\n\n\n
...\nTotal Warnings: 0\nTotal Errors: 0\n\nThings look okay - No serious problems were detected during the pre-flight check<\/code><\/pre>\n\n\n\n
systemctl restart nagios<\/code><\/pre>\n\n\n\n
\/usr\/local\/nagios\/libexec\/check_http -I web01.kifarunix-demo.com -p 443 -C 10<\/code><\/pre>\n\n\n\n
SSL OK - Certificate '*.kifarunix-demo.com' will expire on 2020-10-18 08:21 -0400\/EDT. HTTP OK: HTTP\/1.1 200 OK - 303 bytes in 0.025 second response time |time=0.025159s;;;0.000000 size=303B;;;0<\/code><\/pre>\n\n\n\n
\/usr\/local\/nagios\/libexec\/check_http -I mail.kifarunix-demo.com -p 465 -C 20<\/code><\/pre>\n\n\n\n
SSL WARNING - Certificate 'mx01.kifarunix-demo.com' expires in 12 day(s) (2019-11-08 23:14 +0000\/EDT).<\/code><\/pre>\n\n\n\n
<\/a><\/figure>\n\n\n\n