<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Technical Diary &#187; monitoring</title>
	<atom:link href="http://andriigrytsenko.net/tag/monitoring/feed/" rel="self" type="application/rss+xml" />
	<link>http://andriigrytsenko.net</link>
	<description>With Andrii Grytsenko</description>
	<lastBuildDate>Sun, 01 Apr 2012 11:10:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Nagios3 installation</title>
		<link>http://andriigrytsenko.net/2011/01/nagios3-installation/</link>
		<comments>http://andriigrytsenko.net/2011/01/nagios3-installation/#comments</comments>
		<pubDate>Thu, 27 Jan 2011 18:43:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[monitoring]]></category>
		<category><![CDATA[nagios]]></category>

		<guid isPermaLink="false">http://andriigrytsenko.net/?p=853</guid>
		<description><![CDATA[Nagios installation and basic configuration. INSTALLATION Installation takes just a few easy steps. As I installed it on Debian box so used apt-get for installation: apt-get install nagios3 After nagios was installed I created new monitoring user root with password root123 to have access to web page: htpasswd -cb /etc/nagios3/htpasswd.users root root123 And start new [...]]]></description>
			<content:encoded><![CDATA[<p>Nagios installation and basic configuration.<br />
<span id="more-853"></span></p>
<h3><strong>INSTALLATION</strong></h3>
<p>Installation takes just a few easy steps. As I installed it on Debian box so used apt-get for installation:<br />
<code>apt-get install nagios3</code></p>
<p>After nagios was installed I created new monitoring user <strong>root</strong> with password <strong>root123</strong> to have access to web page:<br />
<code>htpasswd -cb /etc/nagios3/htpasswd.users root root123</code></p>
<p>And start new service:<br />
<code>/etc/init.d/nagios3 start</code></p>
<h3><strong>SETTING UP</strong></h3>
<p><del>All</del> Almost all configuration are stored at <em>/etc/nagios3/conf.d</em>.</p>
<p>I have one administrator and one contact group of course. So I remained example configuration and change only my mail address at <em>contacts_nagios2.cfg</em>:<br />
<code>email                           my@address.com</code></p>
<p>I&#8217;m gonna monitoring 3 linux hosts plus one router with next services:<br />
1. Master</p>
<ul>
<li>dns</li>
<li>httpd</li>
<li>http + ssl</li>
<li>samba</li>
<li>nis</li>
<li>ftp</li>
<li>openvpn  ( don&#8217;t have corresponding script. Probably make my own.)</li>
<li>ping</li>
<li>smtp</li>
<li>imap</li>
<li>mysql</li>
<li>ssh</li>
<li>processes</li>
<li>disk usage</li>
<li>swap utilization</li>
<li>users</li>
<li>uptime</li>
<li>current load</li>
</ul>
<p>2. Slave</p>
<ul>
<li>processes</li>
<li>swap</li>
<li>disk usage</li>
<li>users</li>
<li>http</li>
<li>ssh</li>
<li>current load</li>
<li>ping</li>
<li>uptime</li>
</ul>
<p>3. Test</p>
<ul>
<li>ldap ( was unable  to configure script check through  the tcp_check)</li>
<li>ping</li>
<li>ssh</li>
<li>samba</li>
</ul>
<p>4. Router</p>
<ul>
<li>ping</li>
</ul>
<p>First of all you need to define all hosts in <em>localhost_nagios2.cfg</em>:<br />
<code>define host{<br />
use                     generic-host            ; Name of host template to use<br />
host_name               secondary<br />
alias                   Secondary<br />
address                 192.168.7.177<br />
}</code></p>
<p>Where, <strong>use</strong> refers to <strong>generic-host</strong> in <em>generic-host_nagios2.cfg</em>. I left everything as was:<br />
<code>define host{<br />
name                            generic-host   ; The name of this host template<br />
notifications_enabled           1       ; Host notifications are enabled<br />
event_handler_enabled           1       ; Host event handler is enabled<br />
flap_detection_enabled          1       ; Flap detection is enabled<br />
failure_prediction_enabled      1       ; Failure prediction is enabled<br />
process_perf_data               1       ; Process performance data<br />
retain_status_information       1       ; Retain status information across program restarts<br />
retain_nonstatus_information    1       ; Retain non-status information across program restarts<br />
check_command                   check-host-alive<br />
max_check_attempts              10<br />
notification_interval           0<br />
notification_period             24x7<br />
notification_options            d,u,r<br />
contact_groups                  admins<br />
register                        0       ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!<br />
}<br />
</code></p>
<p>You can customize it &#8211; set group who will be notified in case of emergency and time-frame for notification.</p>
<p>Also you can make  some host groups if you want. It&#8217;s not necessary but it can simplify service management if  you have a lot of hosts. To define host group go to <em>hostgroups_nagios2.cfg</em>:<br />
<code><br />
define hostgroup {<br />
hostgroup_name  all<br />
alias           All Servers<br />
members         *<br />
}define hostgroup {<br />
hostgroup_name  debian-servers<br />
alias           Debian GNU/Linux Servers<br />
members         secondary, master<br />
}</p>
<p></code></p>
<p>Here we created two groups of hosts: <strong>all</strong> and <strong>debian-servers</strong>. <strong>All</strong> contains all defined hosts in configuration and <strong>debian-servers</strong> just a <strong>secondary</strong> and <strong>master</strong> hosts.</p>
<p>And at the end most interesting and most resource-intensive part &#8211; services. For example if you need to monitor HTTP server on host <em>master</em> put next lines in <em>services_nagios2.cfg</em>:<br />
<code><br />
define service {<br />
host_name                  master<br />
service_description             HTTP<br />
check_command                   check_http<br />
use                             generic-service<br />
notification_interval           0<br />
}</code></p>
<p>Next example if you want to just ping router put:<br />
<code>define service {<br />
host_name                  router<br />
service_description             PING<br />
check_command                   check_ping!100.0,20%!500.0,60%<br />
use                             generic-service<br />
notification_interval           0<br />
}</code></p>
<p>If you need sent arguments to monitoring script separate it by <em>&#8216;!&#8217;</em>.<br />
To monitor group of servers use <em>hostgroup_name</em> intead of <em>host_name</em>, like:<br />
<code>hostgroup_name all</code><br />
- to monitoring all servers described in hostgroup <strong>all</strong>.</p>
<p>To monitoring such stuff like disk usage, process, users, swap and memory utilization I followed direction from <a href="http://wiki.nagios.org/index.php/Howtos:checkbyssh_RedHat">official site</a>.</p>
<h3><strong>PROBLEMS</strong></h3>
<p>The mail notifications wasn&#8217;t work for me. I suggest because there is no mail server on box. I tried to described it in the configuration but haven&#8217;t found anything could help me. So I wrote little script to send a mail directly to another smtp server:<br />
<code><br />
#!/usr/bin/perluse strict;<br />
use MIME::Lite;<br />
use Getopt::Long;</p>
<p>my ($to,$subject);<br />
my  $result = GetOptions ("s=s"   =&gt; \$subject, "t=s"  =&gt;  \$to );<br />
my $smtp = 'xxx.xx.xx.xx';<br />
my $from = 'xxx@xxx.net';</p>
<p>while (&lt;&gt;){<br />
my $msg = MIME::Lite-&gt;new(<br />
From    =&gt; $from,<br />
To      =&gt; $to,<br />
Subject =&gt; $subject,<br />
Type     =&gt; 'TEXT',<br />
Data     =&gt; "$_"<br />
);<br />
$msg-&gt;send('smtp',$smtp,Debug=&gt;0);<br />
}</p>
<p></code></p>
<p>Please define variables <em>smtp</em> and <em>to</em> by yourself. And remember that perl modules <a href="http://search.cpan.org/~rjbs/MIME-Lite-3.027/lib/MIME/Lite.pm">MIME::Lite</a> and <a href="http://search.cpan.org/~jv/Getopt-Long-2.38/lib/Getopt/Long.pm">Getopt::Long</a> have to be preinstalled in the system.</p>
<p>And change lines at <em>/etc/nagios3/commands.cfg</em> appropriately:<br />
<code>command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$</code><br />
and<br />
<code> command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /root/scripts/mail.pl -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" -t $CONTACTEMAIL$</code></p>
<p>To those ones:<br />
<code> command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | <span style="color: #ff0000;">/path/to/mail.pl</span> -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" <span style="color: #ff0000;">-t</span> $CONTACTEMAIL$</code><br />
and<br />
<code> command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | <span style="color: #ff0000;">/root/scripts/mail.pl</span> -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" <span style="color: #ff0000;">-t</span> $CONTACTEMAIL$</code></p>
<p>Where, <em>/root/scripts/mail.pl</em> path to script mail.pl which was provided above.</p>
]]></content:encoded>
			<wfw:commentRss>http://andriigrytsenko.net/2011/01/nagios3-installation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Some perl functions for monitoring</title>
		<link>http://andriigrytsenko.net/2009/06/some-perl-functions-for-monitoring/</link>
		<comments>http://andriigrytsenko.net/2009/06/some-perl-functions-for-monitoring/#comments</comments>
		<pubDate>Fri, 12 Jun 2009 15:30:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[monitoring]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://localhost/?p=16</guid>
		<description><![CDATA[I would like to provide you library which was very useful for me during my working under monitoring system. To make it works you have to install next perl libraries : Net::SSH::Expect; Net::SCP::Expect; Net::SFTP::Foreign; Net::FTP; It&#8217;s easy to do through cpan. For example: # cpan i Net::SSH::Expect or download directly from cpan function exec_cmd__ : [...]]]></description>
			<content:encoded><![CDATA[<p>I would like to provide you library which was very useful for me during my working under monitoring system.<br />
<span id="more-16"></span></p>
<p>To make it works you have to install next perl libraries :</p>
<p>Net::SSH::Expect;<br />
Net::SCP::Expect;<br />
Net::SFTP::Foreign;<br />
Net::FTP;</p>
<p>It&#8217;s easy to do through cpan. For example:</p>
<p><code># cpan i Net::SSH::Expect</code></p>
<p>or download directly from <a href="http://cpan.org">cpan</a></p>
<p><strong>function  exec_cmd__ </strong>:</p>
<p>This function execute command at remote host. Example:</p>
<p>exec_cmd__(hostname, username, password, port, command)</p>
<p><strong>function sub transfer_file__ </strong>:</p>
<p>This function  can get or put file to remote host via ssh. Example :</p>
<p>transfer_file__(hostname, username, password, port, source file|directory, destination file|directory, method)</p>
<p>where option &#8220;method&#8221;  can be &#8220;fh&#8221;(means get file from somewhere and put to localhost) or &#8220;th&#8221;(send file to host)</p>
<p><strong>function sub sftp_func__</strong> :</p>
<p>This function can get and send file to remote computer via sftp protocol. Example<br />
sftp_func__(hostname, username, password, port, source file|directory, destination file|directory, method)</p>
<p>Where option &#8220;method&#8221; can be &#8216;get&#8217;(get file from remote host) and &#8216;put&#8217;(put file to remote host) and &#8216;del&#8217;(delete file from remote host )<br />
<em>NOTICE: if you use method &#8220;del&#8221; please specify the target as &#8220;source_file&#8221; and skip &#8220;destination_file&#8221; option</em></p>
<p><strong>function  ftp_func__</strong> :</p>
<p>This function get and delete remote file via ftp protocol. Example:</p>
<p>ftp_func__(hostname, username, password, port, source file|directory, destination file|directory, method)<br />
where option &#8220;method&#8221; can be &#8216;get&#8217; or &#8216;put&#8217;</p>
<p><strong>function get_file_via_ftp__</strong>:</p>
<p>This function is the same to previous one EXCEPT its doesn&#8217;t put a file at remote computer and when its get a file doesn&#8217;t remove it at remote system. Example:</p>
<p>get_file_via_ftp(hostname, username, password, port, source file|directory,  destination file|directory)</p>
<p><strong>function get_yesterday__</strong>:</p>
<p>This function return date of yesterday in format which was got by function as first argument. Example:</p>
<p>get_yesterday__(&#8220;YYYYDDMM&#8221;), get_yesterday__(&#8220;DDMMYYYY&#8221;) and so on.</p>
<p>How it&#8217;s use? Good question :) </p>
<p>Download <a href="http://andriigrytsenko.net/files/monitoring.pm">this</a> library and put into the /usr/lib/perl5/Net/. Ex.:  </p>
<p><code># cp monitoring.pm /usr/lib/perl5/Net/</code></p>
<p>Create new test script :<br />
<code>$ cat > test.pl<br />
#!/usr/bin/perl<br />
use monitoring;<br />
$yesterday=monitoring::get_yesterday__("DDMMYYYY");<br />
print "$yesterday\n";<br />
</code></p>
<p>Set executable rights:<br />
<code>$ chmod +x test.pl</code></p>
<p>And run it:<br />
<code>$ ./test.pl</code><br />
11062009</p>
<p>That&#8217;s all :)</p>
]]></content:encoded>
			<wfw:commentRss>http://andriigrytsenko.net/2009/06/some-perl-functions-for-monitoring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

