<?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>Extempore &#187; code</title>
	<atom:link href="http://michaelhendrickx.com/category/code/feed" rel="self" type="application/rss+xml" />
	<link>http://michaelhendrickx.com</link>
	<description>random ramblings of the disturbed mind</description>
	<lastBuildDate>Tue, 20 Jul 2010 05:39:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>nnscfgmaker.sh: a nagios/nsclient++ cfg maker</title>
		<link>http://michaelhendrickx.com/201001_nnscfgmaker-sh-a-nagiosnsclient-cfg-maker.html</link>
		<comments>http://michaelhendrickx.com/201001_nnscfgmaker-sh-a-nagiosnsclient-cfg-maker.html#comments</comments>
		<pubDate>Thu, 28 Jan 2010 14:27:42 +0000</pubDate>
		<dc:creator>Michael Hendrickx</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[misc]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[monitoring]]></category>
		<category><![CDATA[nagios]]></category>
		<category><![CDATA[zenoss]]></category>

		<guid isPermaLink="false">http://michaelhendrickx.com/?p=241</guid>
		<description><![CDATA[Dear all,
We are in the process of changing the monitoring system on part of our network from Zenoss to Nagios.  This is not a Zenoss vs. Nagios debate, as both products are awesome and do the things they are designed for very well.  We (Christian and myself) use a combination of Cacti for [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://michaelhendrickx.com/wp-content/uploads/2010/01/nagios.jpg" alt="" title="nagios" width="150" height="114" align="right" />Dear all,</p>
<p>We are in the process of changing the monitoring system on part of our network from Zenoss to Nagios.  This is not a Zenoss vs. Nagios debate, as both products are awesome and do the things they are designed for very well.  We (<a href="http://ae.linkedin.com/in/certifiedgeek">Christian</a> and myself) use a combination of <a href="http://www.cacti.net">Cacti</a> for bandwith monitoring and <a href="http://www.zenoss.com">Zenoss</a> for server and device monitoring.  Now, recently we decided to change the latter to <a href="http://www.nagios.org/">Nagios</a>.  It is know for its &#8220;great deal of flexibility when integrating Nagios into their environment&#8221; (Galstad, 2005)</p>
<p>As Zenoss was configured using <a href="http://www.snmp-informant.com/">SNMP Informant</a> to grab information about the MS Windows servers (available disk space, CPU load, etc) and Nagios uses <a href="http://nsclient.org/">NSClient++</a>; one of the time consuming tasks was getting the client on the server (thank you domain <img src='http://michaelhendrickx.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ) and configuring each and every server on the Nagios server.  I guess there should be some sort of discovery tool for Nagios, but I couldn&#8217;t directly find one.  </p>
<p>In order to tackle the copy-pasting for a few dozen config files, and to brush up my bash scripting again, I wrote the <strong>Nagios Nsclient++ cfg maker</strong><span id="more-241"></span>, yeah, what&#8217;s in a name eh.  This client enumerates the target server about what is installed and makes a CFG file based on that.  Oh yeah, we&#8217;re using nagios with its text files, not the SQL version.</p>
<p>You can download it <a href='http://michaelhendrickx.com/wp-content/uploads/2010/01/nnscfgmaker.sh' >here (bash script)</a>.  As it&#8217;s GPL&#8217;d, feel free to change and redistribute it.  As we mainly house HP servers, APC UPS&#8217;s and most of them run Windows (for now, <em>evil laugh</em>), so it&#8217;s a bit windows/hp minded.</p>
<p>The syntax is very easy, just run the script with the hostname of the server that you want to &#8220;enumerate&#8221;.  Doing that, you&#8217;ll have something similar as the output below:</p>
<pre>
mike@mon:/usr/local/nagios/etc/servers$ ./nnscfgmaker.sh server2
Nagios NSclient++ (check_nt) CFG maker

 + logfile: server2.cfg
 + pinging the server.. ok
 + checking of nsclient++ is installed
 + adding hdd c:\
 + adding hdd e:\
 + adding hdd f:\
 + adding hdd g:\
 + adding hdd h:\
 + adding hdd i:\
 + adding process: MS SQL Server (sqlservr.exe)
 + adding service: Automatic Updates (wuauserv)
 + adding service: DNS Client (DNSCache)
 + adding service: Event Log (Eventlog)
 + adding service: Messenger (Messenger)
 + adding service: Server Service (lanmanserver)
 + adding service: Windows Time (w32time)
 + adding service: SNMP service (SNMP)
 + adding service: HP OpenView Ctrl Service (ovctrl)
 + adding service: Backup Exec Server (BackupExecRPCService)
 + adding service: HP Insight Server Agent (CqMgServ)
 + adding service: HP Insight NIC Agent (CpqNicMgmt)
 + adding service: HP Insight Storage Agent (CqMgStor)
 + adding service: TrendMicro OfficeScan NT Listener (tmlisten)
 + adding service: Trendmicro Antivirus RealTime Scan (ntrtscan)
 - done

mike@mon:/usr/local/nagios/etc/servers$
</pre>
<p>This creates a files called server2.cfg, which Nagios can read and process.</p>
<p>Hope you like it, let me know if you have any questions or comments.</p>
<p>Take care,<br />
Michael</p>
<p><span style="color:#808080">Ethan Galstad (2005), Nagios. [online] Available from: <a href="http://archive.fosdem.org/2005/index/interviews/interviews_galstad.html">http://archive.fosdem.org/2005/index/interviews/interviews_galstad.html</a> (Accessed: 28 Jan 2010)</span></p>
]]></content:encoded>
			<wfw:commentRss>http://michaelhendrickx.com/201001_nnscfgmaker-sh-a-nagiosnsclient-cfg-maker.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Find &#8220;similar things&#8221; in Ruby</title>
		<link>http://michaelhendrickx.com/200908_find-similar-things-in-ruby.html</link>
		<comments>http://michaelhendrickx.com/200908_find-similar-things-in-ruby.html#comments</comments>
		<pubDate>Sat, 29 Aug 2009 12:46:07 +0000</pubDate>
		<dc:creator>Michael Hendrickx</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ror]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://michaelhendrickx.com/?p=189</guid>
		<description><![CDATA[For several Ruby on Rails projects I had to come up with &#8220;similar&#8221; results.  These are often results (video&#8217;s, products,places, hobbies, etc) with the greatest number of tags.
Say, you are tagging car pictures on a website, and have the following:
image1.jpg -> ["honda","s2000","convertible","black"]
image2.jpg -> ["honda","civic","blue"]
image3.jpg -> ["lexus","is300","blue"]
image4.jpg -> ["s2000","honda","convertible","silver"]
image5.jpg -> ["toyota","starlet","black"]
Seeing this, you&#8217;d know that [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://michaelhendrickx.com/wp-content/uploads/2009/08/ruby.jpeg" alt="ruby" title="ruby" width="123" height="96" class="alignright size-full wp-image-193" />For several Ruby on Rails projects I had to come up with &#8220;similar&#8221; results.  These are often results (video&#8217;s, products,<a href="http://places.ae/">places</a>, hobbies, etc) with the greatest number of tags.</p>
<p>Say, you are <em>tagging</em> car pictures on a website, and have the following:</p>
<p>image1.jpg -> ["honda","s2000","convertible","black"]<br />
image2.jpg -> ["honda","civic","blue"]<br />
image3.jpg -> ["lexus","is300","blue"]<br />
image4.jpg -> ["s2000","honda","convertible","silver"]<br />
image5.jpg -> ["toyota","starlet","black"]</p>
<p>Seeing this, you&#8217;d know that image1.jpg and image4.jpg are similar pictures.  Or rather &#8220;more similar&#8221; than , say, image1.jpg and image3.jpg.  For this, I wrote below snippet of code.  This goes in the model file, and can be called as &#8220;object.similar&#8221;.  It returns an array of similar &#8220;things&#8221;, sorted on most similar to less similar (hence the results.reverse at the end) </p>
<p>For example:<br />
<strong>
<pre>
  img = Image.find(params[:id])
  @similar_images = img.similar[0..10]
</pre>
<p></strong></p>
<p>Will give you the 10 &#8220;most similar&#8221; images as img.  Well, it gives you the files with the most similar tags.</p>
<pre>
def similar
  tags = self.tags
  results = []
  tags.each do |tag|
    results = results + tag.pictures # or tag.things, tag.products, ...
    results.delete(self)
  end

  # make array into hash
  h = Hash.new
  results.each do |r|
    h[r] = h[r].to_i + 1
  end

  # sort on values
  tmp = h.sort {|a,b| a[1]<=>b[1]}
  results = []
  tmp.each do |t|
    results << t[0]
  end

  results.reverse # return all items, products, ...
end
</pre>
<p>This was written for a new <a href="http://habibi.ae">project coming up</a>, and will be used to do better "similarities matching" for <a href="http://places.ae">places.ae</a>, though for the latter we also had to sort on distance.  (For it's vicinity)</p>
]]></content:encoded>
			<wfw:commentRss>http://michaelhendrickx.com/200908_find-similar-things-in-ruby.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tar based incremental backups</title>
		<link>http://michaelhendrickx.com/200907_tar-based-incremental-backups.html</link>
		<comments>http://michaelhendrickx.com/200907_tar-based-incremental-backups.html#comments</comments>
		<pubDate>Wed, 01 Jul 2009 10:04:28 +0000</pubDate>
		<dc:creator>Michael Hendrickx</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://michaelhendrickx.com/?p=162</guid>
		<description><![CDATA[A small bash script I wrote to have incremental backups done on a unix server, and then pushed to a Windows File system.  On the fileserver, we add this directory to the normal backup.
This is on a mail server, where emails are stored in MailDir format.  We create weekly full backups on sunday, [...]]]></description>
			<content:encoded><![CDATA[<p>A small bash script I wrote to have incremental backups done on a unix server, and then pushed to a Windows File system.  On the fileserver, we add this directory to the normal backup.</p>
<p>This is on a mail server, where emails are stored in <a href="http://en.wikipedia.org/wiki/Maildir">MailDir</a> format.  We create weekly full backups on sunday, and daily incremental.  This script is called daily at night from a cron job.  Gotta love the scripting abilities of bash.</p>
<p>It might help you out, so here goes:</p>
<pre>
#!/bin/bash
# backup script is doing following items
# dump all incremental email into a backup file, gzip the backup file and
# move the file to an external file server

START_TIME=`/bin/date`
echo "backup started at: ${START_TIME}"

DOW_N=`/bin/date +"%w"` # number, 0 (sun), 1 (mon)
DOW_T=`/bin/date +"%F"`

TO_BACKUP="/opt/maildata/"
TEMP_FILE="/tmp/${DOW_T}_mail_backup.tar"
BACKUP_LOG="/tmp/mail.backup"
FILE_SERVER="/mnt/fileserver/" # mounted over SMB

# if it's a sunday, delete the incremental file and take a full backup
if [ ${DOW_N} -eq "0" ]; then
  /bin/rm ${BACKUP_LOG}
fi

/bin/tar -c -f ${TEMP_FILE} --listed-incremental=${BACKUP_LOG} ${TO_BACKUP}
/bin/gzip -f ${TEMP_FILE}
FILE_SIZE=`/bin/ls -lah ${TEMP_FILE}.gz | awk '{ print $5 }'`
/bin/mv ${TEMP_FILE}.gz ${FILE_SERVER}

## report, this goes in an email through cron
END_TIME=`/bin/date`; export END_TIME
echo "backup ended at: ${END_TIME}"
echo "data moved: ${FILE_SIZE}"
</pre>
]]></content:encoded>
			<wfw:commentRss>http://michaelhendrickx.com/200907_tar-based-incremental-backups.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
