<?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>coder . cl &#187; sysadmin</title>
	<atom:link href="http://coder.cl/category/sysadmin/feed/" rel="self" type="application/rss+xml" />
	<link>http://coder.cl</link>
	<description>web developer &#38; system programmer</description>
	<lastBuildDate>Sat, 04 Feb 2012 12:07:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>spam detection, phase 1</title>
		<link>http://coder.cl/2011/04/spam-detection-phase-1/</link>
		<comments>http://coder.cl/2011/04/spam-detection-phase-1/#comments</comments>
		<pubDate>Fri, 22 Apr 2011 21:13:13 +0000</pubDate>
		<dc:creator>Daniel Molina Wegener</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://coder.cl/?p=1446</guid>
		<description><![CDATA[Is very tedious to see you electronic mailboxes to be filled with spam. If you are a web-master or system administrator, you will see that the web site that you are administrating, is usually scrapped by bot software seeking for certain URLs and electronic mail addresses. That is probably the highest origin of the SPAM [...]]]></description>
			<content:encoded><![CDATA[<p>Is very tedious to see you electronic mailboxes to be filled with spam. If you are a web-master or system administrator, you will see that the web site that you are administrating, is usually scrapped by bot software seeking for certain URLs and electronic mail addresses. That is probably the highest origin of the SPAM on the internet. You know that SPAM is, and this experiment should work only with those SPAM that are related to electronic internet email.</p>
<p><span id="more-1446"></span></p>
<blockquote><p>
Spam is the use of electronic messaging systems (including most broadcast media, digital delivery systems) to send unsolicited bulk messages indiscriminately. While the most widely recognized form of spam is e-mail spam, the term is applied to similar abuses in other media: instant messaging spam, Usenet newsgroup spam, Web search engine spam, spam in blogs, wiki spam, online classified ads spam, mobile phone messaging spam, Internet forum spam, junk fax transmissions, social networking spam, television advertising and file sharing network spam.
</p></blockquote>
<p>This experiment requires a fake electronic mail account, a well known internet domain &mdash; which is subject of constant web scrapping seeking for electronic mails &mdash; and the proper software development tools, something flexible like Linux, rather than those very closed platforms like Windows. If your domain is subject of spam: <i>&ldquo;Send the same message indiscriminately to (large numbers of recipients) on the Internet&rdquo;</i>, this experiment probably will solve your common problems with SPAM and will let you build the proper filters on your SPAM filter daemon or service.</p>
<p>Start creating the fake account. For example <a href='mailto:spam-booby@example.org' title='Fake E-Mail for SPAM'><i>spam-booby@example.org</i></a>. This email address will be scrapped by those internet bots that are seeking for email addresses. Create a fake email client, to review and fetch that folder, that will be seriously affected by those SPAM bots. On your well known domain site, for example <a href='http://www.example.org/' title='Fake Domain for SPAM'>www.example.org</a>, put your fake email address that will be subject of web scrapping in a hidden HTML anchor element:</p>
<pre class="brush: html;">
&lt;a href='mailto:spam-booby@example.org'
   style='display:none;'
   title='just fall here fu**ing bot'&gt;
  spam-booby@example.org
&lt;/a&gt;
&lt;a href='mailto:spam-booby@example.org'
   style='visibility:hidden;'
   title='just fall here fu**ing bot'&gt;
  spam-booby@example.org
&lt;/a&gt;
</pre>
<p>Those mail links will not be displayed on the web browser of your customers, so, you will be safe, but those bots are not smart enough to process the <tt>visibility: hidden</tt> or <tt>display: none</tt> CSS properties. If those bots are smart enough to process that CSS property, well, just use some JavaScript trick to hide them, for example with jQuery that should be like:</p>
<pre class="brush: html;">
&lt;a href='mailto:spam-booby@example.org'
   class='please-hide-me'
   title='just fall here fu**ing bot'&gt;
  spam-booby@example.org
&lt;/a&gt;

&lt;script type='text/javascript'&gt;&lt;--//
$(document).ready(function () {
    $('a.please-hide-me').hide();
});
//--&gt;&lt;/script&gt;
</pre>
<p>That will ensure that those email links will be hidden for your customers using a real browser. Wait one week, and you will be collecting SPAM on the fake <a href='mailto:spam-booby@example.org' title='send it here fu**ing bot'>spam-booby@example.org</a> email account. Also, I know that those spam bot constructors are so bad software developers that will not consider the <a href='http://tools.ietf.org/html/rfc2606'>RFC2606</a> referring to example domains, and will use the email addresses on the present article in their spamming tasks.</p>
<p>This is the first phase, on the second phase, I will try to process the collected data from those captured emails. I will begin this experiment with certain domain, and I hope that you will enjoy the results. For the second phase I&#8217;ve chosen Python as primary language, and some tools to download and fetch the email from the fake account, some Bayesian filter classifiers and certain key/value database to speed-up the mail processing functions. I&#8217;ve started collecting data from today :)</p>
<br/><hr height="1px" width="50%" />
<div style='text-align: center !important;'><b>Copyright © 2011 Daniel Molina Wegener</b><br/><b>Atribución-No Comercial-Sin Derivadas 2.0 Chile</b><br/><a target='_new' rel="license" href="http://creativecommons.org/licenses/by-nc-nd/2.0/cl/"><img alt="Creative Commons License" style="border-width:0" src="http://coder.cl.qfl.wpcdn.arcostream.com/cc88x31.png" /></a></div>
<br/><hr height="1px" width="100%" />
<p><small>© Daniel Molina Wegener for <a href="http://coder.cl">coder . cl</a>, 2011. | <a href="http://coder.cl/2011/04/spam-detection-phase-1/">Permalink</a> | <a href="http://coder.cl/2011/04/spam-detection-phase-1/#comments">One comment</a><br/>Post tags: <br/></small></p>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-6234432850133541";
/* main-feed */
google_ad_slot = "0763600725";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
]]></content:encoded>
			<wfw:commentRss>http://coder.cl/2011/04/spam-detection-phase-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>emacs as python ide</title>
		<link>http://coder.cl/2010/09/emacs-as-python-ide/</link>
		<comments>http://coder.cl/2010/09/emacs-as-python-ide/#comments</comments>
		<pubDate>Thu, 30 Sep 2010 19:53:45 +0000</pubDate>
		<dc:creator>Daniel Molina Wegener</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://coder.cl/?p=951</guid>
		<description><![CDATA[Emacs is a powerful text editor. It has an embedded List dialect interpreter, called Emacs-Lisp and it has many extensions &#8212; called Emacs Modes &#8212; to work in various tasks, from programming tasks, IRC clients, MUAs and time organizing tasks. Many people says that Emacs works likely an Operating System, since it has a lot [...]]]></description>
			<content:encoded><![CDATA[<p>Emacs is a powerful text editor. It has an embedded List dialect interpreter, called Emacs-Lisp and it has many extensions &mdash; called Emacs Modes &mdash; to work in various tasks, from <i>programming</i> tasks, <i>IRC clients</i>, <i>MUAs</i> and <i>time organizing tasks</i>. Many people says that Emacs works likely an Operating System, since it has a lot of applications mounted on top of Emacs Lisp. Python Mode (python-mode) in emacs has been extended and it can be used with various tools, turning your Emacs editor in a powerful IDE to work with Python.</p>
<p><span id="more-951"></span></p>
<p><br/></p>
<h3>python-mode</h3>
<p>Emacs is configured through the Lisp dialect Emacs-Lisp. Core configuration directives are processed from the <tt>~/.emacs</tt> file. To enable the <i>python-mode</i>, you just need to load the python-mode each time that your Emacs editor opens a Python file.</p>
<pre class="brush: lisp;">

;;; auto load python-mode
(autoload 'python-mode "python-mode" "Mode for editing Python source files")

;;; enable python-mode on .py files
(setq auto-mode-alist
      (append '(("\\.py" . python-mode)
                ) auto-mode-alist))

;; auto font lock mode
(defvar font-lock-auto-mode-list
  (list 'python-mode))
</pre>
<p>Also i known that each Emacs Mode, has some hooks, and <i>python-mode</i> isn&#8217;t an exception. To customize the <i>python-mode</i> you can use the <i>python-mode-hook</i> variable:</p>
<pre class="brush: lisp;">

(add-hook 'python-mode-hook 'dmw-python-mode-hook)
</pre>
<p>Where, in this case, <i>dmw-python-mode-hook</i> is a symbol pointing to a function called <i>dmw-python-mode-hook</i>:</p>
<pre class="brush: lisp;">

;; python mode hook
(defun dmw-python-mode-hook ()
  (load "py-mode-ext")
  (load "pyp")
  (require 'pycomplete)
  (setq py-indent-offset 4)
  (setq py-smart-indentation t)
  (setq py-continuation-offset 4)
  (setq indent-tabs-mode nil)
  (setq py-pychecker-command "~/bin/pylint_etc_wrapper.py")
  (setq py-pychecker-command-args (quote ("")))
  (autoload 'pymacs-load "pymacs" nil t)
  (autoload 'pymacs-eval "pymacs" nil t)
  (autoload 'pymacs-apply "pymacs")
  (autoload 'pymacs-call "pymacs")
  (setq interpreter-mode-alist(cons '("python" . python-mode)
                                    interpreter-mode-alist))
  (eldoc-mode 1)
  (define-key py-mode-map [f12] 'pyp)
  (define-key py-mode-map "\C-c\C-w" (lambda ()
                                       (interactive)
                                       (command-execute 'py-pychecker-run)))
  (define-key py-mode-map [C-S-iso-lefttab] 'py-complete)
  )
</pre>
<p><br/></p>
<h3>python-mode-hook</h3>
<p>This python-mode-hook function or hook function, enables a series of features for you python-mode. First, it loads <tt>py-mode-ext</tt> and <tt>pyp</tt>, and also loads <tt>pycomplete</tt>. Those tools are part of the <a href="http://page.sourceforge.net/">PAGE &#8211; Python Automatic GUI Generator</a> package. <tt>py-mode-ext</tt> adds some nice functions and commands, like <tt>py-call-pdb</tt>, to begin debugging Python. <tt>pyp</tt> adds a command/function that prints the current expression, or prompts for an expression to print, with the complete code hierarchy as prefix:</p>
<pre class="brush: python;">

def main():
    if len(sys.argv) != 3:
        print &quot;No dialup number\n&quot;
    txtmsg = sys.argv[2]
    number = sys.argv[1]
    number = number.strip()
    for n in [' ', '+', '(', ')', &quot;\s&quot;, &quot;\t&quot;, '-']:
        number = number.replace(n, &quot;&quot;);
    number = '+' + number
    skype = Skype4Py.Skype()
    skype.Attach()
    ### this line was generated with the pyp
    ### command that has the line
    ### (define-key py-mode-map [f12] 'pyp) on the
    ### python-mode-hook
    print 'main: skype =', skype    # dmw   pyp
    message = skype.CreateSms(Skype4Py.smsMessageTypeOutgoing, number)
    message.Body = txtmsg
    message.Send()
</pre>
<p>Finally the <tt>pycomplete</tt> module has a very nice tool to enable Python auto-completion. For example the following code:</p>
<pre class="brush: python;">

class ParentObject:
    parent1 = None
    parent2 = None
    parent3 = None
    def __init__(self, m1, m2, m3):
        self.parent1 = m1
        self.parent2 = m2
    def child(self, m1, m2, m3):
        self.parent3 = ChildObject(m1, m2, m3)
    def nested(self, m1, m2, m3):
        self.parent3.child4 = NestedChild(m1, m2, m3)
    def subnested(self, m1):
        self.parent3.child4.nested4 = SubNestedChild(m1)
        ### here I press ctrl + s + tab
        ### this will run py-complete as the line
        ### (define-key py-mode-map [C-S-iso-lefttab] 'py-complete)
        ### is defined on the python-mode-hook
        str&lt;Ctrl+S+Tab&gt;
    def __repr__(self):
        return &quot;\n-> &quot; + repr(self.__dict__)
</pre>
<p>This will display a window as follows &mdash; where you just need to press <i>mouse-2</i> or the middle button on your mouse to select one completion:</p>
<div class="figure">
<a href="http://coder.cl.qfl.wpcdn.arcostream.com/uploads/2010/09/python-completions.jpg" target="_blank"><img src="http://coder.cl.qfl.wpcdn.arcostream.com/uploads/2010/09/python-completions.jpg" border="0" /></a>
</div>
<p><br/></p>
<h3>pychecker</h3>
<p>Python static checkers are cool, also are tools that you must use in your daily Python programming tasks. For example, on the <a href="http://www.emacswiki.org">Emacs Wiki</a>, you can find <a href="http://www.emacswiki.org/emacs/PythonProgrammingInEmacs">this article</a> about using Emacs as Python IDE. There I&#8217;ve found the <a href="http://bitbucket.org/tavisrudd/pylint_etc_wrapper.py/src/tip/pylint_etc_wrapper.py">pylint_etc_wrapper.py</a> script, which runs three Python static checkers at once: pylint, pychecker, pyflakes and pep8. Running the pychecker script using the <tt>ctrl + c</tt><tt>ctrl + w</tt> key sequence, you will obtain a window similar to the next one, will errors reported from those tools:</p>
<div class="figure">
<a href="http://coder.cl.qfl.wpcdn.arcostream.com/uploads/2010/09/pychecker.jpg" target="_blank"><img src="http://coder.cl.qfl.wpcdn.arcostream.com/uploads/2010/09/pychecker.jpg" border="0" /></a>
</div>
<p>I hope that you will enjoy <a href="http://en.wikipedia.org/wiki/Hacker_(programmer_subculture)">hacking</a> Python from <a href="http://en.wikipedia.org/wiki/Emacs">Emacs</a>, it&#8217;s a great editor. Also you can use the <a href="http://ecb.sourceforge.net/">Emacs Code Browser</a> with Python, I hope that you can find it very interesting.</p>
<br/><hr height="1px" width="50%" />
<div style='text-align: center !important;'><b>Copyright © 2010 Daniel Molina Wegener</b><br/><b>Atribución-No Comercial-Sin Derivadas 2.0 Chile</b><br/><a target='_new' rel="license" href="http://creativecommons.org/licenses/by-nc-nd/2.0/cl/"><img alt="Creative Commons License" style="border-width:0" src="http://coder.cl.qfl.wpcdn.arcostream.com/cc88x31.png" /></a></div>
<br/><hr height="1px" width="100%" />
<p><small>© Daniel Molina Wegener for <a href="http://coder.cl">coder . cl</a>, 2010. | <a href="http://coder.cl/2010/09/emacs-as-python-ide/">Permalink</a> | <a href="http://coder.cl/2010/09/emacs-as-python-ide/#comments">No comment</a><br/>Post tags: <br/></small></p>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-6234432850133541";
/* main-feed */
google_ad_slot = "0763600725";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
]]></content:encoded>
			<wfw:commentRss>http://coder.cl/2010/09/emacs-as-python-ide/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>function prototypes and references in perl</title>
		<link>http://coder.cl/2010/08/function-prototypes-and-references-in-perl/</link>
		<comments>http://coder.cl/2010/08/function-prototypes-and-references-in-perl/#comments</comments>
		<pubDate>Fri, 20 Aug 2010 23:33:49 +0000</pubDate>
		<dc:creator>Daniel Molina Wegener</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://coder.cl/?p=870</guid>
		<description><![CDATA[Some people is considering Perl as a non-friendly language, but in my opinion is a powerful language, not only for its capacity to do text-processing, it also has a lot of modules and extensions which makes it a language of choice for a wide variety of applications. I prefer to code Perl using strict and [...]]]></description>
			<content:encoded><![CDATA[<p>Some people is considering <a href='http://www.perl.org/'>Perl</a> as a non-friendly language, but in my opinion is a powerful language, not only for its capacity to do text-processing, it also has a lot of modules and extensions which makes it a language of choice for a wide variety of applications. I prefer to code <strong>Perl</strong> using <i>strict</i> and function prototypes, so it looks more clean and elegant. Also it supports <i>lambdas</i> for some tasks. Let&#8217;s take look on prototypes and references. You will find interesting topics reading <strong>perlsub(1)</strong> and <strong>perlref(1)</strong>.</p>
<p><span id="more-870"></span></p>
<p>On the Perl language, prototypes usually are absent, since are not required. you just create a function &mdash; anonymous or not &mdash; by writing <i>subs</i>:</p>
<pre class='brush: perl;'>
sub hello_world {
    return "hello world";
}
</pre>
<p>The principle of perl subs, is that you call them with an <i>unique argument</i> and that argument is a list, so that&#8217;s why calling functions in perl do not require the form <i>function(arg1, arg2, arg3)</i>. For example you can call the <tt>hello_world</tt> function with four different forms:</p>
<pre class='brush: perl;'>
print hello_world;        # the mos common form
print &amp;hello_world;       # code reference style
print hello_world();      # the c derived form without arguments
print &amp;hello_world();     # code reference style form without arguments
</pre>
<blockquote><p>
Like many languages, Perl provides for user-defined subroutines. These may be located anywhere in the main program, loaded in from other files via the <tt>do</tt>, <tt>require</tt>, or <tt>use</tt> keywords, or generated on the fly using <tt>eval</tt> or anonymous subroutines. You can even call a function indirectly using a variable containing its name or a CODE reference.
</p></blockquote>
<p>The last two ones are just indicating that <i>the argument list is empty</i>. Have you tried to pass an array or list as argument?</p>
<pre class='brush: perl;'>
sub hello_who {
    my ($who) = @_;
    print &quot;hello ${who}\n&quot;;
}
my @nekos = ('neko', 'core', 'test');
hello_who 'neko';
hello_who @nekos;
hello_who (@nekos);
</pre>
<p>The code above will just print <i>&quot;hello neko&quot;</i> three times, since the argument handling is just requesting the first argument, and it&#8217;s equivalent to call <tt>my $who = shift;</tt>. So, to pass an array or list as argument, you need to pass its reference &mdash; which is handled internally as <i>scalar type</i> in perl:</p>
<pre class='brush: perl;'>
sub hello_who_iterator($) {
    my ($who) = @_;
    foreach my $i (@{$who}) {
        print &quot;hello ${i}\n&quot;;
    }
}
my @nekos = ('neko', 'core', 'test');
hello_who_iterator \@nekos;
hello_who_iterator \@nekos, "hola";
</pre>
<p>The prototyped function above will allow you to handle one argument as reference and ignore the remaining argument, if any. The same happens to <i>hashes</i>, so you can pass three references without problems:</p>
<pre class='brush: perl;'>
sub hello_world_three($$$) {
    my ($a, $h, $s) = @_;
    my @hello_l;
    foreach my $i (@{$a}) {
        if ($h-&gt;{$i}) {
            push @hello_l, &quot;Hello &quot;.$s.' '.$i.' '.$h-&gt;{$i};
        }
    }
    return join(&quot;\n", @hello_l).&quot;\n&quot;;
}
my %saludos = ('Juan' => 'el "Gato"',
               'Pedro' => 'el "Epidemia"',
               'Diego' => 'el "Conejo"',);
my @saludar_a = ('Juan', 'Pedro');
print hello_world_three(\@saludar_a, \%saludos, 'Mr.');
</pre>
<p>But what happens if I pass directly those three arguments, without using their references? The example above will print the following text:</p>
<pre>
Hello Mr. Juan el &quot;Gato&quot;
Hello Mr. Pedro el &quot;Epidemia&quot;
</pre>
<p>If we replace the code to catch directly those arguments, and not their references, we will not get the same result and the function will not do anything&#8230;</p>
<pre class='brush: perl;'>
sub hello_world_three {
    my (@a, %h, $s) = @_;
    my @hello_l;
    foreach my $i (@a) {
        if ($h{$i}) {
            push @hello_l, &quot;Hello &quot;.$s.' '.$i.' '.$h{$i};
        }
    }
    return join(&quot;\n&quot;, @hello_l).&quot;\n&quot;;
}
my %saludos = ('Juan' => 'el "Gato"',
               'Pedro' => 'el "Epidemia"',
               'Diego' => 'el "Conejo"',);
my @saludar_a = ('Juan', 'Pedro');
print hello_world_three(@saludar_a, %saludos, 'Mr.');
</pre>
<p>The example above applies the <i>shift</i> function to the first argument, so the function just receives the <tt>@saludar_a</tt> argument, so <tt>%h</tt> and <tt>$s</tt> arguments will be empty. If you want to pass an array or a hash to a function, you must do it by passing their reference.</p>
<blockquote><p>
Any arguments passed in show up in the array @_. Therefore, if you called a function with two arguments, those would be stored in $_[0] and $_[1]. The array @_ is a local array, but its elements are aliases for the actual scalar parameters.  In particular, if an element $_[0] is updated, the corresponding argument is updated (or an error occurs if it is not updatable). If an argument is an array or hash element which did not exist when the function was called, that element is created only when (and if) it is modified or a reference to it is taken. (Some earlier versions of Perl created the element whether or not the element was assigned to.) Assigning to the whole array @_ removes that aliasing, and does not update any arguments.
</p></blockquote>
<p><br/></p>
<h3>references</h3>
<ul>
<li><strong>perlsub(1)</strong></li>
<li><strong>perlref(1)</strong></li>
</ul>
<br/><hr height="1px" width="50%" />
<div style='text-align: center !important;'><b>Copyright © 2010 Daniel Molina Wegener</b><br/><b>Atribución-No Comercial-Sin Derivadas 2.0 Chile</b><br/><a target='_new' rel="license" href="http://creativecommons.org/licenses/by-nc-nd/2.0/cl/"><img alt="Creative Commons License" style="border-width:0" src="http://coder.cl.qfl.wpcdn.arcostream.com/cc88x31.png" /></a></div>
<br/><hr height="1px" width="100%" />
<p><small>© Daniel Molina Wegener for <a href="http://coder.cl">coder . cl</a>, 2010. | <a href="http://coder.cl/2010/08/function-prototypes-and-references-in-perl/">Permalink</a> | <a href="http://coder.cl/2010/08/function-prototypes-and-references-in-perl/#comments">No comment</a><br/>Post tags: <br/></small></p>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-6234432850133541";
/* main-feed */
google_ad_slot = "0763600725";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
]]></content:encoded>
			<wfw:commentRss>http://coder.cl/2010/08/function-prototypes-and-references-in-perl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>configuring snmptrapd</title>
		<link>http://coder.cl/2010/07/configuring-snmptrapd/</link>
		<comments>http://coder.cl/2010/07/configuring-snmptrapd/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 23:28:27 +0000</pubDate>
		<dc:creator>Daniel Molina Wegener</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://coder.cl/?p=703</guid>
		<description><![CDATA[snmptrapd(8) is a SNMP trap daemon, in other words, it captures SNMP notifications from the network and similar devices. In this post I will try to explain how to configure this daemon to allow a network server to process SNMP traps using both, embeded perl handlers for snmptrapd(8) and plain standard input &#8212; or stdin [...]]]></description>
			<content:encoded><![CDATA[<p><strong>snmptrapd(8)</strong> is a SNMP trap daemon, in other words, it captures SNMP notifications from the network and similar devices. In this post I will try to explain how to configure this daemon to allow a network server to process SNMP traps using both, embeded perl handlers for <strong>snmptrapd(8)</strong> and plain standard input &mdash; or <i>stdin</i> &mdash; handlers.</p>
<p><span id="more-703"></span></p>
<p></p>
<h3>daemon configuration</h3>
<p>The daemon is quite easy to configure, you must setup the <strong>snmptrapd.conf(5snmp)</strong> file. For this configuration, you must read your desired configuration options, such as <i>logging</i> and <i>execution</i>. For example if we have a <i>community</i> called <i>inetsnmp</i>, we can configure the file to allow traps from that community and also configure a trap handler written in perl.</p>
<pre class="brush: bash;">

# configure inetsnmp community to allow logging,
# execution of handlers and network traffic.
authCommunity   log,execute,net         inetsnmp

# perl embeded handler.
perl do "/usr/share/snmp/handler/trapdembed.pl"
</pre>
<p>This configuration is not enough, the <strong>snmptrapd(8)</strong> daemon uses <strong>hosts.allow(5)</strong> facility, so we need to add the proper rule in that file:</p>
<pre class="brush: bash;">

snmptrapd : 192.168.100.0/255.255.255.0 : allow
snmptrapd : 10.10.10.0/255.255.255.0 : allow
</pre>
<p></p>
<h3>the embeded perl handler</h3>
<pre class="brush: perl;">
#!/usr/bin/perl -w
#

# strict perl is better
use strict;
use FileHandle;
use Data::Dumper;
use NetSNMP::TrapReceiver;

# we create a sample/demo log file...
my $log = FileHandle-&gt;new(&quot;/var/log/snmptrapsample.log&quot;, &quot;a+&quot;) ||
    die &quot;Failed to open log file&quot;;

# how we process an SNMP variable
sub process_var {
    my ($var) = @_;
    my %res;
    my $name = &quot;$var-&gt;[0]&quot;;
    my ($vt, $vv) = split /: /, &quot;$var-&gt;[1]&quot;;
    $res{'oid'} = $name;
    $res{'type'} = $vt;
    $res{'value'} = $vv;
    return \%res;
}

# our default receiver
sub default_receiver {
    my ($pdu, $ivars) = @_;
    my %vars;
    $log-&gt;print(Dumper($pdu));
    foreach my $k (@{$_[1]}) {
        $vars{$k-&gt;[0]} = process_var($k);
    }
    $log-&gt;print(Dumper(\%vars));
    $log-&gt;flush;
}

# every OIDs pass through the default_receiver
NetSNMP::TrapReceiver::register(&quot;all&quot;, \&amp;default_receiver) ||
    die &quot;Failed to laod Sample Trap Receiver\n&quot;;

# status message...
print STDERR &quot;Loaded Sample Trap Receiver\n&quot;;
</pre>
<p>This <strong>perl(1)</strong> handler will allow you basically to create a handler which is capable to process SNMP notifications creating two main variables on the handler itself <i>$pdu</i> which is the reference to the <i>%pdu</i> hash and <i>%vars</i> hash. Both hashes contains the proper data to process the request as you want:</p>
<pre class="brush: perl;">

%pdu = {
    'notificationtype' =&gt; 'TRAP',
    'receivedfrom' =&gt; 'UDP: [10.10.10.1]:53951-&gt;[192.168.100.5]',
    'version' =&gt; 1,
    'errorstatus' =&gt; 0,
    'messageid' =&gt; 0,
    'community' =&gt; 'public',
    'transactionid' =&gt; 1,
    'errorindex' =&gt; 0,
    'requestid' =&gt; 1012897136
};

%vars = {
    'IF-MIB::ifDescr' =&gt; {
        'value' =&gt; 'eth0',
        'type' =&gt; 'STRING',
        'oid' =&gt; 'IF-MIB::ifDescr'
    },
    'IF-MIB::ifAdminStatus.1' =&gt; {
        'value' =&gt; '1',
        'type' =&gt; 'INTEGER',
        'oid' =&gt; 'IF-MIB::ifAdminStatus.1'
    },
    'DISMAN-EVENT-MIB::sysUpTimeInstance' =&gt; {
        'value' =&gt; '(0) 0:00:00.00',
        'type' =&gt; 'Timeticks',
        'oid' =&gt; 'DISMAN-EVENT-MIB::sysUpTimeInstance'
    },
    'IF-MIB::ifIndex.1' =&gt; {
        'value' =&gt; '1',
        'type' =&gt; 'INTEGER',
        'oid' =&gt; 'IF-MIB::ifIndex.1'
    },
    'SNMPv2-MIB::snmpTrapOID.0' =&gt; {
        'value' =&gt; 'IF-MIB::linkUp',
        'type' =&gt; 'OID',
        'oid' =&gt; 'SNMPv2-MIB::snmpTrapOID.0'
    },
    'IF-MIB::ifOperStatus.1' =&gt; {
        'value' =&gt; '1',
        'type' =&gt; 'INTEGER',
        'oid' =&gt; 'IF-MIB::ifOperStatus.1'
    }
};
</pre>
<p>Where each OID or variable, can be treated by using the <strong>NetSNMP::OID</strong> package. Fora <i>stdin</i> handler, if you don&#8217;t know about <strong>perl(1)</strong>, the difference is made on the <strong>snmptrapd.conf(5snmp)</strong> file, instead of configuring a global perl script which itself registers which OIDs will handle, you need to configure a global trap handler or each handler for each OID that you want to handle:</p>
<pre class="brush: bash;">

# configure inetsnmp community to allow logging,
# execution of handlers and network traffic.
authCommunity   log,execute,net         inetsnmp

traphandle     default           /usr/share/snmp/handler/defaultstding.py   default
traphandle     IF-MIB::linkUp    /usr/share/snmp/handler/ifuphandler.py     up
</pre>
<p>This will make your script or application to receive the OID data from <i>stdin</i> as follows:</p>
<pre>
router
UDP: [10.10.10.1]:37745->[192.168.100.5]
DISMAN-EVENT-MIB::sysUpTimeInstance 0:0:00:00.00
SNMPv2-MIB::snmpTrapOID.0 IF-MIB::linkUp
IF-MIB::ifIndex.1 1
IF-MIB::ifAdminStatus.1 up
IF-MIB::ifOperStatus.1 up
IF-MIB::ifDescr eth0
</pre>
<p>And also will require that you will enable in some manner the processing of that data as <i>plain text</i>.</p>
<p>Good luck configuring SNMP traps :)</p>
<br/><hr height="1px" width="50%" />
<div style='text-align: center !important;'><b>Copyright © 2010 Daniel Molina Wegener</b><br/><b>Atribución-No Comercial-Sin Derivadas 2.0 Chile</b><br/><a target='_new' rel="license" href="http://creativecommons.org/licenses/by-nc-nd/2.0/cl/"><img alt="Creative Commons License" style="border-width:0" src="http://coder.cl.qfl.wpcdn.arcostream.com/cc88x31.png" /></a></div>
<br/><hr height="1px" width="100%" />
<p><small>© Daniel Molina Wegener for <a href="http://coder.cl">coder . cl</a>, 2010. | <a href="http://coder.cl/2010/07/configuring-snmptrapd/">Permalink</a> | <a href="http://coder.cl/2010/07/configuring-snmptrapd/#comments">No comment</a><br/>Post tags: <br/></small></p>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-6234432850133541";
/* main-feed */
google_ad_slot = "0763600725";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
]]></content:encoded>
			<wfw:commentRss>http://coder.cl/2010/07/configuring-snmptrapd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>integrating kontact and skype</title>
		<link>http://coder.cl/2010/02/integrating-kontact-and-skype/</link>
		<comments>http://coder.cl/2010/02/integrating-kontact-and-skype/#comments</comments>
		<pubDate>Sat, 20 Feb 2010 01:53:25 +0000</pubDate>
		<dc:creator>Daniel Molina Wegener</dc:creator>
				<category><![CDATA[projects]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://coder.cl/?p=627</guid>
		<description><![CDATA[Kontact is my default PIM application. On its configuration we can setup a phone calling program, such as ekiga, skype and others, it just requires a small script, like the one bellow, which I have integrated with KPilot, so I can manage my contacts centered and synchronized. #!/usr/bin/env python # skype_call.py import sys import Skype4Py [...]]]></description>
			<content:encoded><![CDATA[<p><a href='http://userbase.kde.org/Kontact'>Kontact</a> is my default PIM application. On its configuration we can setup a phone calling program, such as ekiga, skype and others, it just requires a small script, like the one bellow, which I have integrated with <a href='http://cvs.codeyard.net/kpilot/'>KPilot</a>, so I can manage my contacts centered and synchronized.</p>
<p><span id="more-627"></span></p>
<pre class="brush: python;">
#!/usr/bin/env python
# skype_call.py
import sys
import Skype4Py

def main():
    if len(sys.argv) != 2:
        print "No dialup number\n"
    number = sys.argv[1]
    number = number.strip()
    for n in [' ', '+', '(', ')', &quot;\s&quot;, &quot;\t&quot;, '-']:
        number = number.replace(n, &quot;&quot;);
    number = '+' + number
    print number, &quot;\n&quot;
    skype = Skype4Py.Skype()
    skype.Attach()
    skype.PlaceCall(number)

if __name__ == '__main__':
    main()
</pre>
<p>Then, on the Kontact configuration, on the address book settings, we configure the path to our script, called <i>skype_call.py</i>, in this case located at my home directory, on my personal scripts folder.</p>
<div class="figure"><a href='http://coder.cl.qfl.wpcdn.arcostream.com/uploads/2010/02/kontact-configuration.jpg' alt='Kontact Configuration' title='Kontact Configuration' target='_blank'><img border='0' alt='Kontact Configuration' title='Kontact Configuration' src='http://coder.cl.qfl.wpcdn.arcostream.com/uploads/2010/02/kontact-configuration.jpg' style='text-align: center; border: 2px solid #000;'></a></div>
<p>One time configured contact, you can call your contacts just by clicking on their phone numbers. Remember that skype needs the format <i>+country_code&mdash;area_code&mdash;phone_number</i>, like <i>+56 (2) 555 55 55</i>.</p>
<div class="figure"><a href='http://coder.cl.qfl.wpcdn.arcostream.com/uploads/2010/02/kontact-calling.jpg' alt='Contact Calling' title='Contact Calling' target='_blank'><img border='0' alt='Contact Calling' title='Contact Calling' src='http://coder.cl.qfl.wpcdn.arcostream.com/uploads/2010/02/kontact-calling.jpg' style='text-align: center; border: 2px solid #000;'></a></div>
<p>Happy internet calling ;)</p>
<br/><hr height="1px" width="50%" />
<div style='text-align: center !important;'><b>Copyright © 2010 Daniel Molina Wegener</b><br/><b>Atribución-No Comercial-Sin Derivadas 2.0 Chile</b><br/><a target='_new' rel="license" href="http://creativecommons.org/licenses/by-nc-nd/2.0/cl/"><img alt="Creative Commons License" style="border-width:0" src="http://coder.cl.qfl.wpcdn.arcostream.com/cc88x31.png" /></a></div>
<br/><hr height="1px" width="100%" />
<p><small>© Daniel Molina Wegener for <a href="http://coder.cl">coder . cl</a>, 2010. | <a href="http://coder.cl/2010/02/integrating-kontact-and-skype/">Permalink</a> | <a href="http://coder.cl/2010/02/integrating-kontact-and-skype/#comments">No comment</a><br/>Post tags: <br/></small></p>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-6234432850133541";
/* main-feed */
google_ad_slot = "0763600725";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
]]></content:encoded>
			<wfw:commentRss>http://coder.cl/2010/02/integrating-kontact-and-skype/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  coder.cl/category/sysadmin/feed/ ) in 0.38760 seconds, on Feb 7th, 2012 at 2:29 am UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on Feb 7th, 2012 at 3:29 am UTC -->
