{"id":46251,"date":"2024-05-15T01:36:30","date_gmt":"2024-05-15T01:36:30","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=46251"},"modified":"2024-05-29T03:05:10","modified_gmt":"2024-05-29T03:05:10","slug":"icinga-tutorials-how-to-monitor-apache2-using-icinga-agent","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/icinga-tutorials-how-to-monitor-apache2-using-icinga-agent\/","title":{"rendered":"icinga tutorials: How to monitor Apache2 using icinga agent"},"content":{"rendered":"\n<p>To monitor Apache2 on an Ubuntu server where Icinga agent is installed, while Icinga server is installed on another Ubuntu server, you can follow these step-by-step instructions. This guide assumes that Icinga 2 and Icinga Web 2 are properly installed and configured on your Icinga server, and the Icinga agent is installed and connected to your Icinga server.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Install Necessary Plugins<\/h2>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">On the Icinga Agent Server: Ensure you have the nagios-plugins package installed, <span class=\"hljs-keyword\">as<\/span> it includes the check <span class=\"hljs-keyword\">for<\/span> Apache. Install it using:\n\n$ sudo apt-<span class=\"hljs-keyword\">get<\/span> update\n$ sudo apt-<span class=\"hljs-keyword\">get<\/span> install nagios-plugins<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Step 2: Configure Icinga Agent<\/h2>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">Check the Apache Status Module: Make sure that the Apache status module is enabled on the Apache server. You can enable it with:\n\n\n$ sudo a2enmod status\n$ sudo systemctl restart apache2\n\nEnsure the \/etc\/apache2\/mods-enabled\/status.conf is configured to allow access from the Icinga server IP. It might look something like this:\n\n\n&lt;Location \/server-status&gt;\n    SetHandler server-status\n    <span class=\"hljs-keyword\">Require<\/span> local\n    <span class=\"hljs-keyword\">Require<\/span> ip <span class=\"hljs-number\">192.168<\/span>.x.x  <span class=\"hljs-comment\"># IP of your Icinga server<\/span>\n&lt;\/Location&gt;\n\nConfigure the Agent: On the Icinga agent, ensure it can execute the Apache check. You might need to create a command in Icinga <span class=\"hljs-keyword\">if<\/span> it doesn\u2019t exist:\n\nobject CheckCommand <span class=\"hljs-string\">\"check_apache_status\"<\/span> {\n    import <span class=\"hljs-string\">\"plugin-check-command\"<\/span>\n    command = &#91; PluginDir + <span class=\"hljs-string\">\"\/check_http\"<\/span> ]\n    arguments = {\n        <span class=\"hljs-string\">\"-H\"<\/span> = <span class=\"hljs-string\">\"$address$\"<\/span>\n        <span class=\"hljs-string\">\"-u\"<\/span> = <span class=\"hljs-string\">\"\/server-status?auto\"<\/span>\n    }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Step 3: Configure Icinga Server<\/h2>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">Define the Host Object: If you haven't already defined the host object for the Apache server in your Icinga configuration, add it:\n\nobject Host \"apache-server\" {\n    import \"generic-host\"\n    address = \"apache-agent-ip\"\n    check_command = \"hostalive\"\n}\n\nDefine Service for Apache Monitoring: Create a service definition to check Apache status:\n\napply Service \"apache-status\" {\n    import \"generic-service\"\n    check_command = \"apache_status\"\n    vars.address = \"$host.address$\"\n    assign where host.name == \"apache-server\"\n}\n\nOR\n\napply Service \"apache-status\" {\n    import \"generic-service\"\n    check_command = \"http\"\n    vars.address = \"$host.address$\"\n    assign where host.name == \"apache-server\"\n}\n\nReload Icinga 2: After making changes to the configuration files, reload the Icinga 2 service to apply the changes:\n\nsudo systemctl reload icinga2<\/code><\/span><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Step 4: Verify the Configuration<\/h2>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">Icinga Web <span class=\"hljs-number\">2<\/span>: Log into Icinga Web <span class=\"hljs-number\">2<\/span> and navigate to the <span class=\"hljs-string\">'Services'<\/span> section. You should see your <span class=\"hljs-keyword\">new<\/span> service <span class=\"hljs-keyword\">for<\/span> monitoring Apache. Verify that it is checking the status <span class=\"hljs-keyword\">as<\/span> expected.\n\nTroubleshooting: If there are issues, check the Icinga <span class=\"hljs-number\">2<\/span> logs <span class=\"hljs-keyword\">for<\/span> any errors related to the Apache checks. The logs are usually located <span class=\"hljs-keyword\">in<\/span> \/<span class=\"hljs-keyword\">var<\/span>\/log\/icinga2\/icinga2.log.<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<script src=\"https:\/\/gist.github.com\/devops-school\/bd7ffeebf73e58641352d532fe8910fb.js\"><\/script>\n","protected":false},"excerpt":{"rendered":"<p>To monitor Apache2 on an Ubuntu server where Icinga agent is installed, while Icinga server is installed on another Ubuntu server, you can follow these step-by-step instructions. This guide assumes&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[8217],"tags":[],"class_list":["post-46251","post","type-post","status-publish","format-standard","hentry","category-icinga"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/46251","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=46251"}],"version-history":[{"count":3,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/46251\/revisions"}],"predecessor-version":[{"id":46263,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/46251\/revisions\/46263"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=46251"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=46251"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=46251"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}