<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Andrés Álvarez</title>
    <link>https://aalvrz.me/</link>
    <description>Recent content on Andrés Álvarez</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Mon, 23 Jan 2023 00:00:00 +0000</lastBuildDate>
    
	<atom:link href="https://aalvrz.me/index.xml" rel="self" type="application/rss+xml" />
    
    
    <item>
      <title>Implementing Rate Limiting in Chalice</title>
      <link>https://aalvrz.me/posts/implementing-rate-limiting-in-chalice/</link>
      <pubDate>Mon, 23 Jan 2023 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/implementing-rate-limiting-in-chalice/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://aws.github.io/chalice/index&#34;&gt;Chalice&lt;/a&gt; (AWS&#39;s Python serverless micro-framework) does not offer built-in support for throttling/rate limiting. In this post I will show you how to implement your own custom rate limiting capabilities for your serverless API.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Setting Up a SQLAlchemy and Pytest Based Test Suite</title>
      <link>https://aalvrz.me/posts/setting-up-a-sqlalchemy-and-pytest-based-test-suite/</link>
      <pubDate>Wed, 25 May 2022 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/setting-up-a-sqlalchemy-and-pytest-based-test-suite/</guid>
      <description>&lt;p&gt;✨ This is an improved article of the previous &lt;a href=&#34;https://aalvrz.me/posts/python-transactional-tests-using-sqlalchemy-pytest-and-factory-boy.html&#34;&gt;Python Transactional Tests Using SQL Alchemy, Pytest, and Factory Boy&lt;/a&gt; article.&lt;/p&gt;
&lt;p&gt;In this post I will show you how you can setup a Pytest test suite that automatically sets up and teardowns your database using SQAlchemy on each test run. It will also provide transactional tests capabilities as described in &lt;a href=&#34;https://aalvrz.me/posts/python-transactional-tests-using-sqlalchemy-pytest-and-factory-boy.html&#34;&gt;Python Transactional Tests Using SQL Alchemy, Pytest, and Factory Boy&lt;/a&gt;.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>How to Test Amazon SES Emails Using Pytest and Moto</title>
      <link>https://aalvrz.me/posts/how-to-test-amazon-ses-emails-using-pytest-and-moto/</link>
      <pubDate>Fri, 30 Jul 2021 09:58:59 -0600</pubDate>
      
      <guid>https://aalvrz.me/posts/how-to-test-amazon-ses-emails-using-pytest-and-moto/</guid>
      <description>&lt;p&gt;In this post I will show you a very neat way to unit test your Amazon SES emails using Pytest and the awesome &lt;a href=&#34;https://github.com/spulec/moto&#34;&gt;Moto&lt;/a&gt; library for mocking AWS services.&lt;/p&gt;
&lt;h2 id=&#34;how-i-define-ses-emails-in-application-code&#34;&gt;How I Define SES Emails in Application Code&lt;/h2&gt;
&lt;p&gt;I like to use a handy base class for preparing and sending SES emails within my application code. Here is a simple example:&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>How to create a 3 Stage Deployment Pipeline With Github Actions</title>
      <link>https://aalvrz.me/posts/how-tocreate-a-3-stage-deployment-pipeline-with-github-actions/</link>
      <pubDate>Tue, 08 Jun 2021 14:34:36 -0600</pubDate>
      
      <guid>https://aalvrz.me/posts/how-tocreate-a-3-stage-deployment-pipeline-with-github-actions/</guid>
      <description>&lt;p&gt;In this post I will show you how to setup a nice 3 stage deployment pipeline that will lint and test your code before deploying to a specific stage, using Github Actions&lt;/p&gt;
&lt;p&gt;I will be simulating a Python application for this post, so you should modify the Python related stuff according to your project.&lt;/p&gt;
&lt;h2 id=&#34;-build-and-test-workflow&#34;&gt;🔧 Build And Test Workflow&lt;/h2&gt;
&lt;p&gt;This workflow will lint, type check, and test the project before deploying to any stage. Create a &lt;code&gt;.github/workflows/build-and-test.yml&lt;/code&gt; file:&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Python Transactional Tests Using SQL Alchemy, Pytest, and Factory Boy</title>
      <link>https://aalvrz.me/posts/python-transactional-tests-using-sqlalchemy-pytest-and-factory-boy/</link>
      <pubDate>Fri, 19 Feb 2021 13:59:36 -0600</pubDate>
      
      <guid>https://aalvrz.me/posts/python-transactional-tests-using-sqlalchemy-pytest-and-factory-boy/</guid>
      <description>&lt;p&gt;🆕 Read the newer and improved post &lt;a href=&#34;https://aalvrz.me/posts/setting-up-a-sqlalchemy-and-pytest-based-test-suite.html&#34;&gt;&lt;em&gt;Setting Up a SQLAlchemy and Pytest Based Test Suite&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;📅 &lt;em&gt;Last Updated on November 26 2021&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Knowing how to integrate SQLAlchemy for your automated tests can be a bit tricky. Even after reading several blog posts on how to implement transactional tests with SQLAlchemy 1.3 and Pytest, it took me a bit of time to make it all play nicely with &lt;a href=&#34;https://factoryboy.readthedocs.io/en/stable/&#34;&gt;Factory Boy&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In this post I will teach you how you that is achieved.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>How to Debug a Chalice App in Vscode</title>
      <link>https://aalvrz.me/posts/how-to-debug-a-chalice-app-in-vscode/</link>
      <pubDate>Thu, 24 Dec 2020 12:53:55 -0600</pubDate>
      
      <guid>https://aalvrz.me/posts/how-to-debug-a-chalice-app-in-vscode/</guid>
      <description>&lt;p&gt;In this post I will show you how you can create a debug configuration in
Visual Studio Code that will allow you to debug a &lt;a href=&#34;https://github.com/aws/chalice/&#34;&gt;Chalice&lt;/a&gt; application
locally.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Django: Adding Context Data to Class Based Views Using Properties</title>
      <link>https://aalvrz.me/posts/django-adding-context-data-to-class-based-views-using-properties/</link>
      <pubDate>Wed, 30 Sep 2020 09:58:57 -0600</pubDate>
      
      <guid>https://aalvrz.me/posts/django-adding-context-data-to-class-based-views-using-properties/</guid>
      <description>&lt;p&gt;When using Class-Based Views in Django, we normally add additional context data
to the view by implementing the &lt;code&gt;get_context_data()&lt;/code&gt; method:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;color:#00a8c8&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#75af00&#34;&gt;MyDetailView&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;DetailView&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;

    &lt;span style=&#34;color:#00a8c8&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#75af00&#34;&gt;get_context_data&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;self&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;args&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;kwargs&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;
        &lt;span style=&#34;color:#111&#34;&gt;context&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;super&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;get_context_data&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;args&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;kwargs&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;
        &lt;span style=&#34;color:#111&#34;&gt;context&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;[&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;foo&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;]&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;bar&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;

        &lt;span style=&#34;color:#00a8c8&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;context&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This works well. But I am very fond of using another approach, so as to not pollute
the &lt;code&gt;get_context_data&lt;/code&gt; method. We can achieve this using properties:&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Django: Custom Middleware for Alerting High Database Querying</title>
      <link>https://aalvrz.me/posts/django-custom-middleware-for-alerting-high-database-querying/</link>
      <pubDate>Wed, 06 May 2020 15:27:47 -0600</pubDate>
      
      <guid>https://aalvrz.me/posts/django-custom-middleware-for-alerting-high-database-querying/</guid>
      <description>&lt;p&gt;In this post I will show you how you can implement a custom &lt;a href=&#34;https://docs.djangoproject.com/en/3.0/topics/http/middleware/&#34;&gt;middleware&lt;/a&gt; that you can use in your development environment to monitor queries to the database in your views when developing Django applications.&lt;/p&gt;
&lt;p&gt;Let&#39;s begin by creating a &lt;code&gt;middleware.py&lt;/code&gt; file (a nice convention) where we will place our new middleware. The middleware is relatively simple and small, this is how it looks like:&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Custom Admin Action Buttons in Django</title>
      <link>https://aalvrz.me/posts/custom-admin-action-buttons-in-django/</link>
      <pubDate>Wed, 29 Apr 2020 12:06:31 -0600</pubDate>
      
      <guid>https://aalvrz.me/posts/custom-admin-action-buttons-in-django/</guid>
      <description>&lt;p&gt;In this post I will explain how you can add custom action buttons in the admin detail view of objects in the Django admin.&lt;/p&gt;
&lt;p&gt;This is the final result we want to achieve:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://aalvrz.me/posts/custom-admin-action-buttons-in-django/custom_admin_buttons.png&#34; alt=&#34;Custom Admin Buttons&#34;&gt;&lt;/p&gt;
&lt;p&gt;These buttons can trigger custom actions that we want to perform on these objects.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Gracefully Exiting Python Context Managers on Ctrl&#43;C</title>
      <link>https://aalvrz.me/posts/gracefully-exiting-python-context-managers-on-ctrl-c/</link>
      <pubDate>Fri, 10 Apr 2020 16:27:41 -0600</pubDate>
      
      <guid>https://aalvrz.me/posts/gracefully-exiting-python-context-managers-on-ctrl-c/</guid>
      <description>&lt;p&gt;In this post I will show you how you can exit gracefully from within a context manager in your Python application.&lt;/p&gt;
&lt;p&gt;Suppose that we provide a context manager that can be used as a session to perform certain tasks. When the context manager is closed, there is some cleanup work to be done. We want this to happen even when the user interrupts the program with &lt;!-- raw HTML omitted --&gt;Ctrl+C&lt;!-- raw HTML omitted --&gt; key.&lt;/p&gt;
&lt;p&gt;This is how we can achieve that:&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Python Log Messages With Dynamic Formatter Variables</title>
      <link>https://aalvrz.me/posts/python-log-messages-with-dynamic-formatter-variables/</link>
      <pubDate>Thu, 02 Apr 2020 16:07:28 -0600</pubDate>
      
      <guid>https://aalvrz.me/posts/python-log-messages-with-dynamic-formatter-variables/</guid>
      <description>&lt;p&gt;In this post I will explain how it is possible to replace logger formatter variables with dynamic values. Take the following log message for example:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;[2020-04-02 15:37:01] myapp INFO: Logged in successfully.
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;What if we wanted to add some additional data after the &lt;code&gt;INFO&lt;/code&gt; part, &lt;em&gt;but&lt;/em&gt; this data is dynamic, or is only available at runtime. Like a username or an app name for example.&lt;/p&gt;
&lt;p&gt;Let&#39;s take a look at how to achieve this.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Django: ORing A List of Q Objects</title>
      <link>https://aalvrz.me/posts/django-oring-list-of-q-objects/</link>
      <pubDate>Sun, 04 Aug 2019 12:35:00 -0600</pubDate>
      
      <guid>https://aalvrz.me/posts/django-oring-list-of-q-objects/</guid>
      <description>&lt;p&gt;Django allows using the OR bitwise operator &lt;code&gt;|&lt;/code&gt; with &lt;code&gt;Q&lt;/code&gt; objects for more complex lookups:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;color:#111&#34;&gt;Q&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;question__startswith&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;Who&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;|&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;Q&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;question__startswith&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;What&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;However this requires explicitely typing each &lt;code&gt;Q&lt;/code&gt; object. How can we apply this OR opperation to all the &lt;code&gt;Q&lt;/code&gt; objects in a list?&lt;/p&gt;
&lt;p&gt;In Python 3 we can do so like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;functools&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;reduce&lt;/span&gt;
&lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;operator&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;__or__&lt;/span&gt;


&lt;span style=&#34;color:#111&#34;&gt;qs&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;MyModel&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;objects&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;filter&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;reduce&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;__or__&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;filters&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Where &lt;code&gt;filters&lt;/code&gt; is a list containing multiple &lt;code&gt;Q&lt;/code&gt; objects like the ones shown in the first example.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Coding Challenge: Rectangular Intersection</title>
      <link>https://aalvrz.me/posts/coding-challenge-rectangular-intersection/</link>
      <pubDate>Tue, 09 Apr 2019 18:07:34 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/coding-challenge-rectangular-intersection/</guid>
      <description>&lt;p&gt;&lt;strong&gt;Difficulty:&lt;/strong&gt; Medium&lt;/p&gt;
&lt;h2 id=&#34;problem&#34;&gt;Problem&lt;/h2&gt;
&lt;p&gt;Given two rectangles, write a function that can find the rectangular intersection between the two rectangles. The rectangles are always straight and never diagonal (each side is parallel with either the x axis or the y axis). Consider only positive axis.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://aalvrz.me/posts/coding-challenge-rectangular-intersection/rectangular_intersection.png&#34; alt=&#34;Rectangular Intersection&#34;&gt;&lt;/p&gt;
&lt;p&gt;The rectangles are defined as a &lt;code&gt;Rectangle&lt;/code&gt; class as shown below:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Rectangle(left_x, bottom_y, width, height)

# Example
r = Rectangle(2, 7, 30 8)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Your output rectangle should be returned using this format.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Coding Challenge: Longest Substring Without Repeating Characters</title>
      <link>https://aalvrz.me/posts/coding-challenge-longest-substring-without-repeating-characters/</link>
      <pubDate>Mon, 08 Apr 2019 15:09:13 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/coding-challenge-longest-substring-without-repeating-characters/</guid>
      <description>&lt;p&gt;&lt;strong&gt;Difficulty:&lt;/strong&gt; Easy&lt;/p&gt;
&lt;h2 id=&#34;problem&#34;&gt;Problem&lt;/h2&gt;
&lt;p&gt;Given a string, find the length of the longest substring without repeating characters.&lt;/p&gt;
&lt;p&gt;Examples:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Given &lt;code&gt;abcabcbb&lt;/code&gt;, the answer is &lt;code&gt;abc&lt;/code&gt;, which the length is 3.&lt;/li&gt;
&lt;li&gt;Given &lt;code&gt;bbbbb&lt;/code&gt;, the answer is &lt;code&gt;b&lt;/code&gt;, with the length of 1.&lt;/li&gt;
&lt;li&gt;Given &lt;code&gt;pwwkew&lt;/code&gt;, the answer is &lt;code&gt;wke&lt;/code&gt;, with the length of 3. Note that the answer must be a &lt;strong&gt;substring&lt;/strong&gt;, &lt;code&gt;pwke&lt;/code&gt; is a &lt;em&gt;subsequence&lt;/em&gt; and not a substring.&lt;/li&gt;
&lt;/ul&gt;</description>
    </item>
    
    <item>
      <title>Custom Log Files With Django and Elastic Beanstalk</title>
      <link>https://aalvrz.me/posts/custom-log-files-with-django-and-elastic-beanstalk/</link>
      <pubDate>Fri, 22 Feb 2019 17:49:21 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/custom-log-files-with-django-and-elastic-beanstalk/</guid>
      <description>&lt;p&gt;With Amazon ElasticBeanstalk it is possible to view log files of your deployed application. However, ElasticBeanstalk by default only returns certain logs like &lt;code&gt;/var/log/httpd/error_log&lt;/code&gt; or &lt;code&gt;/var/log/httpd/access_log&lt;/code&gt; if you are using Apache httpd.&lt;/p&gt;
&lt;p&gt;If you are generating custom logs in your Django application and using file handlers to save them to log files, you will probably want to be able to access and read them easily from the ElasticBeanstalk console.&lt;/p&gt;
&lt;p&gt;In this post I will show you how to achieve this, using Django as our backend framework.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Making Functions Timeout in Python</title>
      <link>https://aalvrz.me/posts/making-functions-timeout-in-python/</link>
      <pubDate>Wed, 06 Feb 2019 16:02:35 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/making-functions-timeout-in-python/</guid>
      <description>&lt;p&gt;Sometimes you need to execute a function that can take a lot of time to finish. You are not sure exactly when the function will finish, but you do not want to wait too long, or let your program &amp;ldquo;hang&amp;rdquo; waiting for a response.&lt;/p&gt;
&lt;p&gt;We want our function to run for a certain period of time, and if this time limit is exceeded, we want to regain control of the program&#39;s execution.&lt;/p&gt;
&lt;p&gt;We can achieve this by using a custom &lt;a href=&#34;http://book.pythontips.com/en/latest/context_managers.html&#34;&gt;context manager&lt;/a&gt; and the &lt;a href=&#34;https://docs.python.org/2/library/signal.html&#34;&gt;&lt;code&gt;signal&lt;/code&gt;&lt;/a&gt; module from the Python standard library.&lt;/p&gt;
&lt;p&gt;Here is a complete example:&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Dropdown Toolbar Buttons in Netbeans Platform</title>
      <link>https://aalvrz.me/posts/dropdown-toolbar-buttons-in-netbeans-platform/</link>
      <pubDate>Tue, 05 Feb 2019 20:16:38 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/dropdown-toolbar-buttons-in-netbeans-platform/</guid>
      <description>&lt;p&gt;It is possible to add buttons that toggle a dropdown menu to the main toolbar in your Netbeans Platform application.&lt;/p&gt;
&lt;p&gt;For example, the Netbeans IDE &lt;em&gt;Run Project&lt;/em&gt;, &lt;em&gt;Debug Project&lt;/em&gt;, and &lt;em&gt;Profile Project&lt;/em&gt; buttons have a small arrow next to them. When clicked, a dropdown menu with more related actions is shown:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://aalvrz.me/posts/dropdown-toolbar-buttons-in-netbeans-platform/netbeans_ide_dropdown_actions.png&#34; alt=&#34;Netbeans IDE Dropdown Buttons&#34;&gt;&lt;/p&gt;
&lt;p&gt;In this article, I will teach you how to implement this behavior.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Setting Up Elastic Beanstalk Health Checks With a Django Application</title>
      <link>https://aalvrz.me/posts/setting-up-elastic-beanstalk-health-checks-with-a-django-application/</link>
      <pubDate>Tue, 15 Jan 2019 20:33:50 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/setting-up-elastic-beanstalk-health-checks-with-a-django-application/</guid>
      <description>&lt;p&gt;I was having an issue the past few days with Django and Elastic Beanstalk in a production environment that was driving me nuts.&lt;/p&gt;
&lt;p&gt;Basically the Elastic Beanstalk environment was in a permament Severe/Degraded state. The health monitoring was reporting that 100% of the requests to the load balancer were &lt;code&gt;4xx&lt;/code&gt; requests:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://aalvrz.me/posts/setting-up-elastic-beanstalk-health-checks-with-a-django-application/eb_unhealthy_400_requests.png&#34; alt=&#34;Elastic Beanstalk 4xx requests&#34;&gt;&lt;/p&gt;
&lt;p&gt;This issue was probably caused by several reasons. In this post I will go over the possible causes, and how I managed to resolve this issue.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Media-Type Based Responses With Django REST Framework</title>
      <link>https://aalvrz.me/posts/media-type-based-responses-with-django-rest-framework/</link>
      <pubDate>Wed, 09 Jan 2019 17:28:17 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/media-type-based-responses-with-django-rest-framework/</guid>
      <description>&lt;p&gt;Nowadays a typical REST API responds with data in JSON format. But what if you wanted to serve data in a different format (and not just a serialization format) using the &lt;strong&gt;same&lt;/strong&gt; endpoint, but specified by the client?&lt;/p&gt;
&lt;p&gt;Django REST Framework &lt;a href=&#34;https://www.django-rest-framework.org/api-guide/renderers/&#34;&gt;renderers&lt;/a&gt; can help us achieve this nice feature.&lt;/p&gt;
&lt;h2 id=&#34;use-case-onix-for-books-compatible-api&#34;&gt;Use Case: ONIX For Books Compatible API&lt;/h2&gt;
&lt;p&gt;&lt;a href=&#34;https://en.wikipedia.org/wiki/ONIX_for_Books&#34;&gt;ONIX for books&lt;/a&gt; is an XML format for sharing bibliographic data pertaining to both traditional books and eBooks.&lt;/p&gt;
&lt;p&gt;Let&#39;s say our application serves metadata about books (title, author, etc.) in the usual JSON format, but we also want to provide data in &lt;a href=&#34;https://www.editeur.org/83/Overview/&#34;&gt;ONIX&lt;/a&gt; format, which is an XML standard that defines how the metadata should be described and put together for consumption.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Python Functional Testing for AWS Lambda</title>
      <link>https://aalvrz.me/posts/python-functional-testing-for-aws-lambda/</link>
      <pubDate>Wed, 26 Dec 2018 17:17:28 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/python-functional-testing-for-aws-lambda/</guid>
      <description>&lt;p&gt;In this post I will explain and go over how I personally write functional tests for my AWS Lambda functions.&lt;/p&gt;
&lt;p&gt;For our example use case, we will assume that our Lambda function is quite complex, as in that it involves downloading a file, processing it, and uploading a result. Additionally it will be called by an SQS event, and it make use of other non-Python related elements, as we will see later.&lt;/p&gt;
&lt;p&gt;Let&#39;s get started!&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Pytest Tricks for Better Python Tests</title>
      <link>https://aalvrz.me/posts/pytest-tricks-for-better-python-tests/</link>
      <pubDate>Fri, 21 Dec 2018 21:03:28 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/pytest-tricks-for-better-python-tests/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://pytest.org/&#34;&gt;Pytest&lt;/a&gt; is my Python testing framework of choice. Very easy to use, and makes tests look much better.&lt;/p&gt;
&lt;p&gt;In this article I&#39;ll show you some cool tricks I have incorporated into my test suites using Pytest.&lt;/p&gt;
&lt;h2 id=&#34;environment-variables&#34;&gt;Environment Variables&lt;/h2&gt;
&lt;p&gt;When your application must work with defined environment variables, the testing environment must have these variables defined as well, even if the values are not real.&lt;/p&gt;
&lt;p&gt;With Pytest we can easily configure any necessary environment variables in our test environment. We simply create a fixture in &lt;code&gt;conftest.py&lt;/code&gt; that will be loaded automatically:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# conftest.py&lt;/span&gt;

&lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;pytest&lt;/span&gt;


&lt;span style=&#34;color:#75af00&#34;&gt;@pytest.fixture&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;autouse&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;True&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;
&lt;span style=&#34;color:#00a8c8&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#75af00&#34;&gt;env_setup&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;monkeypatch&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;
    &lt;span style=&#34;color:#111&#34;&gt;monkeypatch&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;setenv&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;MY_SETTING&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;some-value&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;
    &lt;span style=&#34;color:#111&#34;&gt;monkeypatch&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;setenv&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;ANOTHER_SETTING&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;some-value&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;a href=&#34;https://docs.pytest.org/en/latest/monkeypatch.html&#34;&gt;&lt;code&gt;monkeypatch&lt;/code&gt;&lt;/a&gt; is a built-in pytest fixture that allows us to set environment variables in the test runs. By enabling the &lt;code&gt;autouse&lt;/code&gt; option, our custom environment setup fixture will be automatically called in every test without having to include it explicitly using the usual dependency injection mechanism.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>CloudFront CORS Font Issues</title>
      <link>https://aalvrz.me/posts/cloudfront-cors-font-issues/</link>
      <pubDate>Wed, 12 Dec 2018 16:32:22 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/cloudfront-cors-font-issues/</guid>
      <description>&lt;p&gt;I was experiencing an issue with CloudFront and some static assets of a Django application deployed to ElasticBeanstalk. The issue was happening when trying to retrieve some fonts that are stored in S3 and served by CloudFront, the browser dev tools would show some errors similar to the following:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Access to Font at &#39;http://CLOUDFRONT_HOSTNAME.cloudfront.net/FONT_PATH&#39; from origin &#39;http://www.example.com&#39; has been blocked by CORS policy: No &#39;Access-Control-Allow-Origin&#39; header is present on the requested resource.
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A &lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS&#34;&gt;CORS&lt;/a&gt; issue. And apparently, very common when trying to load fonts.&lt;/p&gt;
&lt;p&gt;To fix this, there are a few possible things that you might have to try. I will list some of the fixes I found.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Cancellable Tasks in Netbeans Platform</title>
      <link>https://aalvrz.me/posts/cancellable-tasks-in-netbeans-platform/</link>
      <pubDate>Wed, 28 Nov 2018 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/cancellable-tasks-in-netbeans-platform/</guid>
      <description>&lt;p&gt;I was trying to implement cancellable tasks in Netbeans Platform using &lt;a href=&#34;https://rubenlaguna.com/post/2010-01-18-cancellable-tasks-and-progress-indicators-netbeans-platform/&#34;&gt;this blog post&lt;/a&gt; as reference.&lt;/p&gt;
&lt;p&gt;However I never managed to make it work. The tasks&#39;s thread would never get interrupted even after the confirmation dialog, the task would just keep running.&lt;/p&gt;
&lt;p&gt;After some digging on the Netbeans Platform and IDE &lt;a href=&#34;https://github.com/apache/incubator-netbeans&#34;&gt;source code&lt;/a&gt;, I think I managed to find a way to properly and &lt;strong&gt;easily&lt;/strong&gt; implement cancellable tasks.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Recursive Python AWS Lambda Functions</title>
      <link>https://aalvrz.me/posts/recursive-python-aws-lambda-functions/</link>
      <pubDate>Tue, 18 Sep 2018 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/recursive-python-aws-lambda-functions/</guid>
      <description>&lt;p&gt;There are times where some processing task cannot be completed under the AWS Lambda timeout limit (a maximum of 5 minutes as of this writing). A possible solution for these kind of situations is to implement a recursive approach to perform the processing task.&lt;/p&gt;
&lt;p&gt;Basically, if you are able to separate the task into multiple chunks or batches, then you could make each batch to be processed by a different Lambda function. The amount of Lambda functions necessary to finish the task will scale accordingly.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Displaying Images in Netbeans Platform Node Tooltips</title>
      <link>https://aalvrz.me/posts/displaying-images-in-netbeans-platform-node-tooltips/</link>
      <pubDate>Tue, 14 Aug 2018 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/displaying-images-in-netbeans-platform-node-tooltips/</guid>
      <description>&lt;p&gt;Netbeans Platform allows you to display HTML inside a node&#39;s tooltip text. Naturally this means you can display images. For example, project nodes in the Netbeans IDE display icons related to errors (if there are any) and version control:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://aalvrz.me/posts/displaying-images-in-netbeans-platform-node-tooltips/node_tooltip_images.png&#34; alt=&#34;Netbeans Node Tooltip Images&#34;&gt;&lt;/p&gt;
&lt;p&gt;Achieving this is not very straight forward, since the documentation doesn&#39;t really say much on how to load this image. Fortunately it is very simple.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Troubleshooting Strange AWS Issues</title>
      <link>https://aalvrz.me/posts/troubleshooting-strange-aws-issues/</link>
      <pubDate>Tue, 07 Aug 2018 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/troubleshooting-strange-aws-issues/</guid>
      <description>&lt;p&gt;We&#39;ve all been there. The same things working fine one time but failing other times without any idea why.&lt;/p&gt;
&lt;p&gt;This post is a list of troubleshooting strange issues I&#39;ve encountered when using AWS.&lt;/p&gt;
&lt;h2 id=&#34;elasticbeanstalk-failing-to-create-rds-security-group&#34;&gt;ElasticBeanstalk Failing to Create RDS Security Group&lt;/h2&gt;
&lt;p&gt;I was having an issue where I couldn&#39;t create and attach an RDS database to an ElasticBeanstalk environment because an RDS security group was failing at being created. All this was being done using the AWS console.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Loosely Coupled Node Actions in Netbeans Platform</title>
      <link>https://aalvrz.me/posts/loosely-coupled-node-actions-in-netbeans-platform/</link>
      <pubDate>Wed, 25 Jul 2018 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/loosely-coupled-node-actions-in-netbeans-platform/</guid>
      <description>&lt;p&gt;Nodes in Netbeans Platform can possess actions that can be executed with the node object as context. For example, the Project, Package, and Class nodes in the Netbeans IDE have a set of actions which can be seen by right clicking on the nodes:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://aalvrz.me/posts/loosely-coupled-node-actions-in-netbeans-platform/netbeans_ide_node_actions.png&#34; alt=&#34;Netbeans IDE Node Actions&#34;&gt;&lt;/p&gt;
&lt;p&gt;In the Netbeans Platform tutorials I found &lt;a href=&#34;https://platform.netbeans.org/tutorials/nbm-nodesapi2.html#actions&#34;&gt;a tutorial&lt;/a&gt; that explains how to add these actions to nodes. The problem is that in that tutorial the action class was created as an &lt;strong&gt;inner class&lt;/strong&gt; of the node class. Making the action &lt;strong&gt;tightly coupled&lt;/strong&gt; with the node.&lt;/p&gt;
&lt;p&gt;I managed to implement a more modular and loosely coupled approach, which is what I will explain in this post.&lt;/p&gt;
&lt;p&gt;Our loosely coupled approach will basically allow us to:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Keep the domain logic (Java Beans and POJOs) in its own domain module.&lt;/li&gt;
&lt;li&gt;Keep the view logic (nodes that represent beans) in another module.&lt;/li&gt;
&lt;li&gt;Keep the node actions logic in yet another module. This allows us to plug and unplug different action&#39;s that belong to separate modules. Making our application&#39;s node actions very modular.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Let&#39;s begin!&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Netbeans Platform Status Bars</title>
      <link>https://aalvrz.me/posts/netbeans-platform-status-bars/</link>
      <pubDate>Thu, 19 Jul 2018 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/netbeans-platform-status-bars/</guid>
      <description>&lt;p&gt;In desktop applications, status bars are a great way to convey information to the user about the current status of certain items in the application, such as connection status, total amount of items, current mode, current row and column number in an editor, etc.&lt;/p&gt;
&lt;p&gt;Implementing custom status bars to a Netbeans Platform application is extremely easy. In this article I will go over how we can achieve really cool things with status bars and lookups.&lt;/p&gt;
&lt;h2 id=&#34;creating-and-registering-a-new-status-bar&#34;&gt;Creating and Registering a New Status Bar&lt;/h2&gt;
&lt;p&gt;To create a new status bar, create a new Java class that implements the &lt;code&gt;StatusLineElementProvider&lt;/code&gt; interface. To register it as a status bar, we use the &lt;code&gt;@ServiceProvider&lt;/code&gt; annotation:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-java&#34; data-lang=&#34;java&#34;&gt;&lt;span style=&#34;color:#75af00&#34;&gt;@ServiceProvider&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;service&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;StatusLineElementProvider&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#75af00&#34;&gt;class&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;position&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;1&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;)&lt;/span&gt;
&lt;span style=&#34;color:#00a8c8&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#00a8c8&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#75af00&#34;&gt;MyStatusBar&lt;/span&gt; &lt;span style=&#34;color:#00a8c8&#34;&gt;implements&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;StatusLineElementProvider&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;{&lt;/span&gt;

&lt;span style=&#34;color:#f92672&#34;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
    </item>
    
    <item>
      <title>Implementing Auto Updates for a Netbeans Platform Maven Application Using Github Pages</title>
      <link>https://aalvrz.me/posts/implementing-auto-updates-for-a-netbeans-platform-maven-application-using-github-pages/</link>
      <pubDate>Tue, 17 Jul 2018 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/implementing-auto-updates-for-a-netbeans-platform-maven-application-using-github-pages/</guid>
      <description>&lt;p&gt;Being able to update an application when a new version is released is something of critical importance for desktop applications. Otherwise, the process of updating the application is extremely tedious since you have to download more installers all the time.&lt;/p&gt;
&lt;p&gt;Luckily, Netbeans Platform comes with integrated support for enabling your custom applications to be able to be updated when a new version is released.&lt;/p&gt;
&lt;p&gt;In this post I will go over how to implement this on a &lt;strong&gt;Maven&lt;/strong&gt; based Netbeans Platform application.&lt;/p&gt;
&lt;h2 id=&#34;how-netbeans-update-center-works&#34;&gt;How Netbeans Update Center Works&lt;/h2&gt;
&lt;p&gt;The &lt;strong&gt;Update Center&lt;/strong&gt; is how we can achieve this functionality. The way it works is that you publish your module&#39;s NBM files to a web server, along with a XML catalog file that contains information about the modules such as latest release timestamp, latest version, etc.&lt;/p&gt;
&lt;p&gt;When you configure an update center in your application, you will configure this web server&#39;s URL so that the update center client knows where to poll and where to download the new module files to install.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>BytesIO File Uploads to Django Using Requests</title>
      <link>https://aalvrz.me/posts/bytesio-file-uploads-to-django-using-requests/</link>
      <pubDate>Tue, 26 Jun 2018 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/bytesio-file-uploads-to-django-using-requests/</guid>
      <description>&lt;p&gt;It&#39;s very easy to post file data to Django using requests:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;requests&lt;/span&gt;


&lt;span style=&#34;color:#111&#34;&gt;requests&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;post&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;url&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;files&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;{&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;cover&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;open&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;imgpath.jpg&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;rb&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;However I was having a hard time getting that to work using &lt;a href=&#34;https://wiki.python.org/moin/BytesIO&#34;&gt;BytesIO&lt;/a&gt;. The reason I wanted to use BytesIO was because I was reading the file binary data located in S3, from AWS Lambda. I didn&#39;t want to write the file to disk first and then do something like the code shown above.&lt;/p&gt;
&lt;p&gt;Here&#39;s how to achieve that:&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Using Listeners in Custom Netbeans Platform Wizards</title>
      <link>https://aalvrz.me/posts/using-listeners-in-custom-netbeans-platform-wizards/</link>
      <pubDate>Tue, 22 May 2018 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/using-listeners-in-custom-netbeans-platform-wizards/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://platform.netbeans.org/tutorials/nbm-wizard.html#validate&#34;&gt;This tutorial&lt;/a&gt; explains how you can add validation to your custom wizards in the Netbeans Platform. This works by setting a boolean variable to &lt;code&gt;false&lt;/code&gt; and then throwing a &lt;code&gt;WizardValidationException&lt;/code&gt; which will show an error message in the wizard, disabling the ability to click the &lt;em&gt;Next&lt;/em&gt; or &lt;em&gt;Finish&lt;/em&gt; buttons.&lt;/p&gt;
&lt;p&gt;The problem with this is that after the above happens, there is no way to enable these buttons again. And the way to achieve this is not covered in that tutorial.&lt;/p&gt;
&lt;p&gt;Therefore, in this blog post I will explain just how to do that.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Netbeans Platform Node Icon Badges</title>
      <link>https://aalvrz.me/posts/netbeans-platform-node-icon-badges/</link>
      <pubDate>Thu, 03 May 2018 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/netbeans-platform-node-icon-badges/</guid>
      <description>&lt;p&gt;The Netbeans IDE has some very cool way of letting users know when a certain file contains errors. For example, if you are editing a Java file and the file contains syntax errors, Netbeans will change the file icons with a new icon indicating errors:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://aalvrz.me/posts/netbeans-platform-node-icon-badges/netbeans_error_icons.png&#34; alt=&#34;Netbeans Error Icons&#34;&gt;&lt;/p&gt;
&lt;p&gt;You can see that the error icons propagate all the way up to the top-most parent, the project itself.&lt;/p&gt;
&lt;h2 id=&#34;netbeans-platform-icon-badges&#34;&gt;Netbeans Platform Icon Badges&lt;/h2&gt;
&lt;p&gt;As a user of the Netbeans IDE and before even knowing what the Netbeans Platform was, I always assumed that the normal state of the icon and the error state of the icon were two completely different icons handled by Netbeans. A few days ago I learned that this is not the case.&lt;/p&gt;
&lt;p&gt;Netbeans uses the concept of &lt;strong&gt;icon badges&lt;/strong&gt; to display these kind of error icons. Icon badges are basically multiple images merged together &lt;em&gt;at runtime&lt;/em&gt; into a single &lt;code&gt;Image&lt;/code&gt; object.&lt;/p&gt;
&lt;p&gt;In this article I want to quickly go over how you can apply this concept in your Netbeans Platform application when using the Nodes API.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Creating Toolbars for MultiView Elements in Netbeans Platform</title>
      <link>https://aalvrz.me/posts/creating-toolbars-for-multiview-elements-in-netbeans-platform/</link>
      <pubDate>Mon, 23 Apr 2018 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/creating-toolbars-for-multiview-elements-in-netbeans-platform/</guid>
      <description>&lt;p&gt;On a &lt;a href=&#34;https://aalvrz.me/posts/custom-file-types-in-netbeans-platform.html&#34;&gt;previous post&lt;/a&gt; I talked about creating a new file type that Netbeans Platform can recognize and display the file&#39;s data in different ways by creating different visual editors that implement the &lt;code&gt;MultiViewElement&lt;/code&gt; interface.&lt;/p&gt;
&lt;p&gt;However, that tutorial did not cover how to add a custom toolbar to each multi view. Like the one Netbeans already provides when editing source code:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://aalvrz.me/posts/creating-toolbars-for-multiview-elements-in-netbeans-platform/netbeans_multiview_toolbar.png&#34; alt=&#34;Netbeans MultiView Toolbar&#34;&gt;&lt;/p&gt;
&lt;p&gt;This is a very handy toolbar that can be used to add buttons that perform different kinds of actions with the current active file.&lt;/p&gt;
&lt;h2 id=&#34;a-deeper-look-into-the-multiviewelement-object&#34;&gt;A Deeper Look Into the MultiViewElement Object&lt;/h2&gt;
&lt;p&gt;If you recall from the previous post, a &lt;code&gt;JPanel&lt;/code&gt; that implements &lt;code&gt;MultiViewElement&lt;/code&gt; was created after finishing the wizard. This &lt;code&gt;MultiViewElement&lt;/code&gt; object has some very important characteristics that are key to this tutorial:&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Django Formsets with Generic FormViews</title>
      <link>https://aalvrz.me/posts/django-formsets-with-generic-formviews/</link>
      <pubDate>Thu, 19 Apr 2018 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/django-formsets-with-generic-formviews/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://docs.djangoproject.com/en/2.0/topics/forms/formsets/&#34;&gt;Django Formsets&lt;/a&gt; is an extremely handy feature for handling multiple clones of forms in a single view. In this post I will go over how to implement them using one of Django&#39;s built-in generic class based views, the &lt;a href=&#34;https://docs.djangoproject.com/en/2.0/ref/class-based-views/generic-editing/#django.views.generic.edit.FormView&#34;&gt;FormView&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;the-scenario&#34;&gt;The Scenario&lt;/h2&gt;
&lt;p&gt;To add some context to this tutorial, let&#39;s say we want to implement one of those kind of nested searches you see on some sites. Where you can select a field from a dropdown, and type in a search value for each field. Fields can be added and removed dynamically using JavaScript. Something like this:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://aalvrz.me/posts/django-formsets-with-generic-formviews/nested_search_example.png&#34; alt=&#34;Nested Search Example&#34;&gt;&lt;/p&gt;
&lt;p&gt;For this tutorial, we will use the following model as an example:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;color:#00a8c8&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#75af00&#34;&gt;Book&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;models&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;Model&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;
    &lt;span style=&#34;color:#111&#34;&gt;title&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;models&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;CharField&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;
    &lt;span style=&#34;color:#111&#34;&gt;author&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;models&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;ForeignKey&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;Author&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;
    &lt;span style=&#34;color:#111&#34;&gt;isbn&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;models&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;CharField&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;
    &lt;span style=&#34;color:#111&#34;&gt;editorial&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;models&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;ForeignKey&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;Editorial&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;creating-the-form&#34;&gt;Creating the Form&lt;/h2&gt;
&lt;p&gt;We will begin by creating the form that will be cloned. That is, the form that will represent &lt;strong&gt;one&lt;/strong&gt; search query out of the many that will/could be nested together.&lt;/p&gt;
&lt;p&gt;For our case, the form will only contain 3 fields:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The query field: Indicates which field of the model we will query.&lt;/li&gt;
&lt;li&gt;The lookup type: Indicates which &lt;a href=&#34;https://docs.djangoproject.com/en/2.0/topics/db/queries/#field-lookups&#34;&gt;lookup&lt;/a&gt; is going to be used to make the query.&lt;/li&gt;
&lt;li&gt;The query value: Indicates what we want to actually search for (i.e &lt;em&gt;Harry Potter&lt;/em&gt; for the book title.)&lt;/li&gt;
&lt;/ol&gt;</description>
    </item>
    
    <item>
      <title>Custom File Types in Netbeans Platform</title>
      <link>https://aalvrz.me/posts/custom-file-types-in-netbeans-platform/</link>
      <pubDate>Wed, 28 Mar 2018 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/custom-file-types-in-netbeans-platform/</guid>
      <description>&lt;p&gt;If your desktop Java application needs to deal with very particular or special kinds of files, we can make use of Netbeans Platform&#39;s custom File Type feature to define a file that our application can recognize, and display visual and editing components to view and edit the file&#39;s data.&lt;/p&gt;
&lt;p&gt;Moreover, we can also make use of Netbeans Platform&#39;s &lt;em&gt;Favorites&lt;/em&gt; pane, which displays a tree view of a file system, where we can open the special files we need to work with.&lt;/p&gt;
&lt;h2 id=&#34;creating-a-new-module&#34;&gt;Creating a New Module&lt;/h2&gt;
&lt;p&gt;For this article, we are going to create a new file type for CSV (Comma Separated Value) files. When we open these files, our application will display a visual representation in the form of an editable JTable.&lt;/p&gt;
&lt;p&gt;All this functionaltiy will live in its own Netbeans Platform Module. Meaning that it can be plugged in into different applications in a modular fashion.&lt;/p&gt;
&lt;p&gt;We are going to create the module and build it using &lt;a href=&#34;https://maven.apache.org/&#34;&gt;Maven&lt;/a&gt;, since we are also going to be adding some functionalities that depend on external libraries that we can easily include in our project with Maven. But you can also just create the module without Maven as well. To create the module go to &lt;em&gt;New Project &amp;gt; Maven &amp;gt; Netbeans Module&lt;/em&gt;&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Testing Django and DRF With Pytest</title>
      <link>https://aalvrz.me/posts/testing-django-and-drf-with-pytest/</link>
      <pubDate>Fri, 09 Feb 2018 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/testing-django-and-drf-with-pytest/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://docs.pytest.org/en/latest/contents.html&#34;&gt;Pytest&lt;/a&gt; has become my favorite Python testing framework. And in this article I want to go over on how I learned to write nice tests for Django and &lt;a href=&#34;http://www.django-rest-framework.org/&#34;&gt;Django REST Framework&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;We will be using the following tools:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://docs.pytest.org/en/latest/contents.html&#34;&gt;Pytest&lt;/a&gt;: Python testing framework&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://pytest-django.readthedocs.io/&#34;&gt;pytest-django&lt;/a&gt;: Pytest extensions for Django&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://factoryboy.readthedocs.io/&#34;&gt;factoryboy&lt;/a&gt;: Factories for easy test data generation.&lt;/li&gt;
&lt;/ul&gt;</description>
    </item>
    
    <item>
      <title>Building a Django Continuous Integration and Delivery Pipeline to AWS</title>
      <link>https://aalvrz.me/posts/building-a-django-continuous-integration-and-delivery-pipeline-to-aws/</link>
      <pubDate>Tue, 30 Jan 2018 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/building-a-django-continuous-integration-and-delivery-pipeline-to-aws/</guid>
      <description>&lt;p&gt;Building a CI/CD (Continuous Integration / Continuous Delivery) flow for your web application is a must nowadays. With so many things that can go wrong, and the amount of time and effort the deployment process of an application takes, a flow like this will give you peace of mind that your application is running without (or with less) errors and that your application will be production ready on every new commit to its source code.&lt;/p&gt;
&lt;p&gt;In this post I want to talk about building such a pipeline, with emphasis on deploying a Django 1.11 application to AWS ElasticBeanstalk, which is an Amazon service very similar to &lt;a href=&#34;https://www.heroku.com/&#34;&gt;Heroku&lt;/a&gt;. Additionally I will talk about how to include other services to the delivery flow, such as Amazon S3 for storage of static files and Amazon RDS (Relational Database Service) for a relational database that will be connected to our application.&lt;/p&gt;
&lt;p&gt;The pipeline will work as follows:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Code will be pushed to source control repository. For this article, I will use Github.&lt;/li&gt;
&lt;li&gt;Project will be built and tested in a CI job at &lt;a href=&#34;https://travis-ci.com/&#34;&gt;TravisCI&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;TravisCI will perform a deployment to ElasticBeanstalk once the build passes successfully.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;We will be using both the &lt;strong&gt;&lt;a href=&#34;https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3.html&#34;&gt;ElasticBeanstalk CLI (ebcli)&lt;/a&gt;&lt;/strong&gt; and the &lt;strong&gt;AWS ElasticBeanstalk Console&lt;/strong&gt; to achieve this.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Django Dynamic Queryset Filtering With Pagination</title>
      <link>https://aalvrz.me/posts/django-dynamic-queryset-filtering-with-pagination/</link>
      <pubDate>Wed, 17 Jan 2018 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/django-dynamic-queryset-filtering-with-pagination/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://simpleisbetterthancomplex.com/tutorial/2016/11/28/how-to-filter-querysets-dynamically.html&#34;&gt;This blog article&lt;/a&gt; does a very good job at explaining how to setup dynamic queryset filtering in Django. However, it doesn&#39;t go into paginating the filtered queryset results.&lt;/p&gt;
&lt;p&gt;I had a very hard time trying to implement this pagination feature using &lt;strong&gt;class based views&lt;/strong&gt;. More specifically, using the &lt;code&gt;FilterView&lt;/code&gt; that comes with the &lt;a href=&#34;https://github.com/carltongibson/django-filter&#34;&gt;django-filter&lt;/a&gt; package.&lt;/p&gt;
&lt;p&gt;In the end it turned out to be very simple. The &lt;a href=&#34;https://django-filter.readthedocs.io/en/master/guide/usage.html#generic-view-configuration&#34;&gt;documentation&lt;/a&gt; was a bit misleading on this so it took a while to understand and find the solution.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Django AJAX Search With Elasticsearch</title>
      <link>https://aalvrz.me/posts/django-ajax-search-with-elasticsearch/</link>
      <pubDate>Wed, 10 Jan 2018 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/django-ajax-search-with-elasticsearch/</guid>
      <description>&lt;p&gt;In this post I want to go over how I implemented a very neat AJAX search using Elasticsearch in Django. Let&#39;s get started!&lt;/p&gt;
&lt;h2 id=&#34;the-search-template&#34;&gt;The Search Template&lt;/h2&gt;
&lt;p&gt;The starting point of our search feature will be the search template. That is, the template that contains the input field where the user will type in the search keywords.&lt;/p&gt;
&lt;p&gt;This template is extremely simple and does not need a &lt;code&gt;&amp;lt;form&amp;gt;&lt;/code&gt; tag. I will create it as a partial under &lt;code&gt;templates/search.html&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-liquid&#34; data-lang=&#34;liquid&#34;&gt;{% csrf_token %}
&amp;lt;input id=&amp;quot;search&amp;quot; name=&amp;quot;q&amp;quot; placeholder=&amp;quot;Search...&amp;quot;&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Notice how we have given the input a &lt;code&gt;name&lt;/code&gt; with the value of &lt;code&gt;q&lt;/code&gt;. This will be important when our view receives the query from this input field.&lt;/p&gt;
&lt;p&gt;I can then render this partial in the main template like this:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-liquid&#34; data-lang=&#34;liquid&#34;&gt;{% include &#39;search.html&#39; %}
&lt;/code&gt;&lt;/pre&gt;</description>
    </item>
    
    <item>
      <title>Java JTable Tricks</title>
      <link>https://aalvrz.me/posts/java-jtable-tricks/</link>
      <pubDate>Wed, 20 Dec 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/java-jtable-tricks/</guid>
      <description>&lt;p&gt;Java&#39;s JTable is a GUI component that has been around for many many years. While a bit difficult to work with, it&#39;s almost a mandatory component in an application that displays a lot of data.&lt;/p&gt;
&lt;p&gt;In this post I share some nice tricks for working with JTables in Java applications.&lt;/p&gt;
&lt;h2 id=&#34;scrolling&#34;&gt;Scrolling&lt;/h2&gt;
&lt;p&gt;A JTable by itself does not provide any scrolling when handling a lot of data. To fix this, we need to place the table inside a &lt;code&gt;JScrollPane&lt;/code&gt; component. Additionally, we can place this &lt;code&gt;JScrollPane&lt;/code&gt; into a &lt;code&gt;JPanel&lt;/code&gt; in our window:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-java&#34; data-lang=&#34;java&#34;&gt;&lt;span style=&#34;color:#111&#34;&gt;myPanel&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#75af00&#34;&gt;add&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#00a8c8&#34;&gt;new&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;JScrollPane&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;myTable&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;,&lt;/span&gt;
    &lt;span style=&#34;color:#111&#34;&gt;JScrollPane&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#75af00&#34;&gt;VERTICAL_SCROLLBAR_AS_NEEDED&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;,&lt;/span&gt;
    &lt;span style=&#34;color:#111&#34;&gt;JScrollPane&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#75af00&#34;&gt;HORIZONTAL_SCROLLBAR_AS_NEEDED&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;)&lt;/span&gt;
    &lt;span style=&#34;color:#f92672&#34;&gt;)&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
    </item>
    
    <item>
      <title>Bulk Create With Django REST Framework</title>
      <link>https://aalvrz.me/posts/bulk-create-with-django-rest-framework/</link>
      <pubDate>Mon, 27 Nov 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/bulk-create-with-django-rest-framework/</guid>
      <description>&lt;p&gt;In this quick post I will go over how to create an endpoint that allows bulk creation of a resource using &lt;a href=&#34;http://www.django-rest-framework.org/&#34;&gt;Django REST Framework&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;the-serializer&#34;&gt;The Serializer&lt;/h2&gt;
&lt;p&gt;Let&#39;s assume that we will be working with an existing &lt;code&gt;Book&lt;/code&gt; model in our Django application. We will create a serializer for this model using Django REST&#39;s &lt;a href=&#34;http://www.django-rest-framework.org/api-guide/serializers/#modelserializer&#34;&gt;ModelSerializer&lt;/a&gt; helper class:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# serializers.py&lt;/span&gt;
&lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;myapp.models&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;Book&lt;/span&gt;
&lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;rest_framework&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;serializers&lt;/span&gt;


&lt;span style=&#34;color:#00a8c8&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#75af00&#34;&gt;BookSerializer&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;serializers&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;ModelSerializer&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;
    &lt;span style=&#34;color:#00a8c8&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#75af00&#34;&gt;Meta&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;
        &lt;span style=&#34;color:#111&#34;&gt;model&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;Book&lt;/span&gt;
        &lt;span style=&#34;color:#111&#34;&gt;fields&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;__all__&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The &lt;code&gt;&amp;quot;__all__&amp;quot;&lt;/code&gt; string indicates that we want to serialize &lt;strong&gt;all&lt;/strong&gt; of the model&#39;s fields.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Building an OCR Service With TesseractJS in AWS Lambda</title>
      <link>https://aalvrz.me/posts/building-an-ocr-service-with-tesseractjs-in-aws-lambda/</link>
      <pubDate>Tue, 21 Nov 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/building-an-ocr-service-with-tesseractjs-in-aws-lambda/</guid>
      <description>&lt;p&gt;The past few days I was trying to make &lt;a href=&#34;https://github.com/naptha/tesseract.js&#34;&gt;TesseractJS&lt;/a&gt; work in &lt;a href=&#34;https://aws.amazon.com/lambda/&#34;&gt;AWS Lambda&lt;/a&gt; so that I could do some OCR (Optical Character Recognition) on some images I had stored in an S3 bucket. However I am a bit new to NodeJS and I was running into some difficulties getting it to work in the Lambda environment. In this post I am going to go through some of these issues and how I solved them.&lt;/p&gt;
&lt;p&gt;TesseractJS is a OCR library written in pure JavaScript. It can recognize the text in images, as well as provide information about the location of the paragraphs, lines, and words in the document.&lt;/p&gt;
&lt;p&gt;We will be using a &lt;strong&gt;NodeJS 6.10&lt;/strong&gt; runtime in AWS Lambda. And I will be deploying the service with &lt;a href=&#34;https://claudiajs.com/&#34;&gt;ClaudiaJS&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;downloading-the-tesseractjs-files&#34;&gt;Downloading the TesseractJS Files&lt;/h2&gt;
&lt;p&gt;When running TesseractJS to recognize an image, TesseractJS will automatically begin downloading some files, which include tesseract language files, a core library file, and a worker file. These are all files that TesseractJS requires in order to correctly run.&lt;/p&gt;
&lt;p&gt;The problem occurs when trying to download these inside AWS Lambda, since Lambda only allows writing to the &lt;code&gt;/tmp/&lt;/code&gt; directory, you will get an error like this in your logs:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Error: EROFS: read-only file system, open &#39;eng.traineddata&#39;
&lt;/code&gt;&lt;/pre&gt;</description>
    </item>
    
    <item>
      <title>Creating an Upload Progress Dialog in Java</title>
      <link>https://aalvrz.me/posts/creating-an-upload-progress-dialog-in-java/</link>
      <pubDate>Thu, 16 Nov 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/creating-an-upload-progress-dialog-in-java/</guid>
      <description>&lt;p&gt;Many Java file upload &lt;a href=&#34;http://www.codejava.net/coding/swing-application-to-upload-files-to-ftp-server-with-progress-bar&#34;&gt;tutorials&lt;/a&gt; teach you how to show the current progress of a file upload using a JProgressBar in the user interface, usually placed in the main JFrame.&lt;/p&gt;
&lt;p&gt;However I was trying make this much more visually appealing, like the way &lt;a href=&#34;https://winscp.net/eng/index.php&#34;&gt;WinSCP&lt;/a&gt; does it:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://aalvrz.me/posts/creating-an-upload-progress-dialog-in-java/scp_file_upload.png&#34; alt=&#34;SCP File Upload&#34;&gt;&lt;/p&gt;
&lt;p&gt;This will require the use of another Swing class: JDialog. Basically the flow of the program will be like this:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Main class with main method calls &lt;code&gt;SwingWorker&lt;/code&gt; class.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;SwingWorker&lt;/code&gt; is in charge of doing the &lt;em&gt;actual&lt;/em&gt; upload. It will also create an instance of a &lt;code&gt;JDialog&lt;/code&gt; to show the current upload progress.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;JDialog&lt;/code&gt; class will contain the progress bar and other useful upload information.&lt;/li&gt;
&lt;/ol&gt;</description>
    </item>
    
    <item>
      <title>Querying Nested Documents in ElasticSearch</title>
      <link>https://aalvrz.me/posts/querying-nested-documents-in-elasticsearch/</link>
      <pubDate>Mon, 23 Oct 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/querying-nested-documents-in-elasticsearch/</guid>
      <description>&lt;p&gt;The other day I was using ElasticSearch to build an index that would contain book documents. These book documents would then contain many pages, each page indicating its page number in the book, and its content as text, extrated from its own PDF file.&lt;/p&gt;
&lt;p&gt;I wanted to perform some queries on a specific book so that ElasticSearch would return all the pages in the book which contained a certain word in its &lt;code&gt;text&lt;/code&gt; field.&lt;/p&gt;
&lt;h2 id=&#34;nested-documents&#34;&gt;Nested Documents&lt;/h2&gt;
&lt;p&gt;ElasticSearch 5 supports &lt;a href=&#34;&#34;&gt;nested documents&lt;/a&gt;. These are internally separate documents that will belong to a certain parent, in this case, a book. Before creating any books, we must first define a &lt;a href=&#34;https://www.elastic.co/guide/en/elasticsearch/guide/current/nested-mapping.html&#34;&gt;nested object mapping&lt;/a&gt; for the index:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;PUT /my_index

{
  &amp;quot;mappings&amp;quot;: {
    &amp;quot;book&amp;quot;: {
      &amp;quot;properties&amp;quot;: {
        &amp;quot;pages&amp;quot;: {
          &amp;quot;type&amp;quot;: &amp;quot;nested&amp;quot;,
          &amp;quot;properties&amp;quot;: {
            &amp;quot;id&amp;quot;:    { &amp;quot;type&amp;quot;: &amp;quot;integer&amp;quot;  },
            &amp;quot;text&amp;quot;: { &amp;quot;type&amp;quot;: &amp;quot;text&amp;quot;  },
          }
        }
      }
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Notice how the mapping is created using a &lt;code&gt;PUT&lt;/code&gt; request at the &lt;strong&gt;index&lt;/strong&gt; level.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Umask Permissions in a Puma Production Environment</title>
      <link>https://aalvrz.me/posts/umask-permissions-in-a-puma-production-environment/</link>
      <pubDate>Wed, 18 Oct 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/umask-permissions-in-a-puma-production-environment/</guid>
      <description>&lt;p&gt;Recently I was having an issue with a Sinatra application deployed in a staging
server. The application was deployed with Puma and Nginx in the following location:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;/var/www/
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This web service would then try to access some files in another directory on the server,
mounted as an SFTP directory. The Sinatra app would open these files and generate some
new files from them, depending on the HTTP request received.&lt;/p&gt;
&lt;p&gt;The problem was that the operation would fail due to a permissions issue. I was baffled
since I had set &lt;strong&gt;read&lt;/strong&gt; and &lt;strong&gt;write&lt;/strong&gt; permissions to the directory and the files in it.&lt;/p&gt;
&lt;h2 id=&#34;umask-the-problem-and-solution&#34;&gt;Umask: The Problem and Solution&lt;/h2&gt;
&lt;p&gt;It took around two days to find the culprit: &lt;strong&gt;umask&lt;/strong&gt;. In Linux, &lt;a href=&#34;https://askubuntu.com/questions/44542/what-is-umask-and-how-does-it-work&#34;&gt;umask&lt;/a&gt;
acts as another set of permissions for &lt;strong&gt;processes&lt;/strong&gt; and cannot be set for directories,
basically speaking.&lt;/p&gt;
&lt;p&gt;I realized that this probably meant that the process running the Puma application server had
a umask configuration that was not allowing the generation of new files.&lt;/p&gt;
&lt;p&gt;I decided to test this if this was the case. In the &lt;a href=&#34;https://github.com/puma/puma&#34;&gt;Puma&lt;/a&gt;
documentation, I found an option to change the permissions of the UNIX socket using
umask:&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Easy Notification System in Rails Part 3</title>
      <link>https://aalvrz.me/posts/easy-notification-system-in-rails-part-3/</link>
      <pubDate>Tue, 12 Sep 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/easy-notification-system-in-rails-part-3/</guid>
      <description>&lt;p&gt;&lt;em&gt;Read &lt;a href=&#34;https://aalvrz.me/posts/easy-notification-system-in-rails.html&#34;&gt;part 1&lt;/a&gt; and &lt;a href=&#34;https://aalvrz.me/posts/easy-notification-system-in-rails-part-2.html&#34;&gt;part 2&lt;/a&gt; of this series&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;In this post, we will be sending automatic e-emails every time notifications are created.&lt;/p&gt;
&lt;h2 id=&#34;creating-the-mailer&#34;&gt;Creating the Mailer&lt;/h2&gt;
&lt;p&gt;We will work with one &lt;a href=&#34;http://guides.rubyonrails.org/action_mailer_basics.html&#34;&gt;mailer&lt;/a&gt; that will send e-mails for every notification that is created. We can generate our mailer with this command:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;rails g mailer NotificationsMailer
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Our mailer will contain an action for each notifiable type that works with notifications in our application. In this series, we&#39;ve been using &lt;strong&gt;comments&lt;/strong&gt; and &lt;strong&gt;posts&lt;/strong&gt; as examples.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Easy Notification System in Rails Part 2</title>
      <link>https://aalvrz.me/posts/easy-notification-system-in-rails-part-2/</link>
      <pubDate>Tue, 05 Sep 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/easy-notification-system-in-rails-part-2/</guid>
      <description>&lt;p&gt;&lt;em&gt;Read Part 1 of this series &lt;a href=&#34;https://aalvrz.me/posts/easy-notification-system-in-rails.html&#34;&gt;here&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;In Part 1 we learned how to setup our models and controllers to create notifications using callbacks in our application. Then we displayed these notifications in a Bootstrap 3 navbar using JQuery written in CoffeeScript.&lt;/p&gt;
&lt;p&gt;In this post we will be adding more functionality to our notification system.s&lt;/p&gt;
&lt;h2 id=&#34;mark-as-read-feature&#34;&gt;Mark as Read Feature&lt;/h2&gt;
&lt;p&gt;We will be adding a feature that allows the current user to mark a notification as read as well as all notifications, in the following manner:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;For a single notification, it should be marked &lt;em&gt;as read&lt;/em&gt; when it is clicked from the list of notifications.&lt;/li&gt;
&lt;li&gt;For all notifications, they should be marked as read when a specific button is pressed.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;setting-up-the-routes&#34;&gt;Setting up the Routes&lt;/h3&gt;
&lt;p&gt;Let&#39;s begin adding the necessary routes. In part 1 we defined a &lt;code&gt;notifications&lt;/code&gt; resource. We will add a &lt;a href=&#34;http://guides.rubyonrails.org/routing.html#adding-more-restful-actions&#34;&gt;collection&lt;/a&gt; POST route and a &lt;a href=&#34;http://guides.rubyonrails.org/routing.html#adding-more-restful-actions&#34;&gt;member&lt;/a&gt; POST route of the same name:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-ruby&#34; data-lang=&#34;ruby&#34;&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# config/routes.rb&lt;/span&gt;
&lt;span style=&#34;color:#00a8c8&#34;&gt;Rails&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;application&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;routes&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;draw&lt;/span&gt; &lt;span style=&#34;color:#00a8c8&#34;&gt;do&lt;/span&gt;
  &lt;span style=&#34;color:#75715e&#34;&gt;# ...&lt;/span&gt;

  &lt;span style=&#34;color:#111&#34;&gt;resources&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;:notifications&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;only&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;[&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;:index&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;]&lt;/span&gt; &lt;span style=&#34;color:#00a8c8&#34;&gt;do&lt;/span&gt;
    &lt;span style=&#34;color:#111&#34;&gt;post&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;:mark_as_read&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;on&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;:collection&lt;/span&gt;
    &lt;span style=&#34;color:#111&#34;&gt;post&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;:mark_as_read&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;on&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;:member&lt;/span&gt;
  &lt;span style=&#34;color:#00a8c8&#34;&gt;end&lt;/span&gt;

&lt;span style=&#34;color:#00a8c8&#34;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
    </item>
    
    <item>
      <title>Easy Notification System in Rails</title>
      <link>https://aalvrz.me/posts/easy-notification-system-in-rails/</link>
      <pubDate>Mon, 04 Sep 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/easy-notification-system-in-rails/</guid>
      <description>&lt;p&gt;Having a notification system is very common for a web application. In this post I will go over how to implement your own simple and easy notification system for your Rails application.&lt;/p&gt;
&lt;p&gt;This post is heavily inspired by &lt;a href=&#34;https://gorails.com/episodes/in-app-navbar-notifications?autoplay=1&#34;&gt;Chris Oliver&#39;s In-App Navbar Notifications tutorial&lt;/a&gt;, with a few personal changes and additions.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Read &lt;a href=&#34;https://aalvrz.me/posts/easy-notification-system-in-rails-part-2.html&#34;&gt;part 2&lt;/a&gt; of this series.&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&#34;models-and-routes&#34;&gt;Models and Routes&lt;/h2&gt;
&lt;p&gt;Before starting with the models, lets quickly define the application resources in our routes:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-ruby&#34; data-lang=&#34;ruby&#34;&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# config/routes.rb&lt;/span&gt;
&lt;span style=&#34;color:#00a8c8&#34;&gt;Rails&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;application&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;routes&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;draw&lt;/span&gt; &lt;span style=&#34;color:#00a8c8&#34;&gt;do&lt;/span&gt;

  &lt;span style=&#34;color:#111&#34;&gt;devise_for&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;:users&lt;/span&gt;

  &lt;span style=&#34;color:#111&#34;&gt;resources&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;:posts&lt;/span&gt; &lt;span style=&#34;color:#00a8c8&#34;&gt;do&lt;/span&gt;
    &lt;span style=&#34;color:#111&#34;&gt;resources&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;:comments&lt;/span&gt;
  &lt;span style=&#34;color:#00a8c8&#34;&gt;end&lt;/span&gt;

  &lt;span style=&#34;color:#111&#34;&gt;resources&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;:notifications&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;only&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;[&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;:index&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;]&lt;/span&gt;

&lt;span style=&#34;color:#00a8c8&#34;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;the-notification-model&#34;&gt;The Notification Model&lt;/h3&gt;
&lt;p&gt;We will manually generate the notification model which will handle the storing of notifications in the database. We can generate a very basic model like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;rails g model Notification recipient_id:integer actor_id:integer read_at:datetime action:string notifiable_id:integer notifiable_type:string
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Here is an explanation for some of the fields for the above model:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;recipient_id&lt;/code&gt;: Represents the user in your application which will receive the notification.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;actor_id&lt;/code&gt;: Represents the user in your application which &lt;em&gt;triggered&lt;/em&gt; the notification.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;read_at&lt;/code&gt;: The time when the notification was read. A value of &lt;code&gt;nil&lt;/code&gt; is used for unread notifications.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;notifiable_id&lt;/code&gt;: The object that represents this notification (a post, comment, etc). This will be a polymorphic association.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;notifiable_type&lt;/code&gt;: Type of the notifiable object. This is usually represented by a humanized (and optionally, internationalized) string form of the object&#39;s class.&lt;/li&gt;
&lt;/ul&gt;</description>
    </item>
    
    <item>
      <title>Integrating Devise With Rolify in Rails</title>
      <link>https://aalvrz.me/posts/integrating-devise-with-rolify-in-rails/</link>
      <pubDate>Thu, 24 Aug 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/integrating-devise-with-rolify-in-rails/</guid>
      <description>&lt;p&gt;I have searched through tons of StackOverflow questions and blog posts on how to &lt;strong&gt;properly&lt;/strong&gt; integrate Rolify with Devise when &lt;strong&gt;registering as a new user&lt;/strong&gt; through the registration view provided by Devise. All proposed solutions and half-solutions seemed very messy to me, but I found a very simple way to achieve this.&lt;/p&gt;
&lt;h2 id=&#34;preparing-the-roles&#34;&gt;Preparing the Roles&lt;/h2&gt;
&lt;p&gt;Assuming you already have initialized a Devise &lt;code&gt;User&lt;/code&gt; model along with a Rolify &lt;code&gt;Role&lt;/code&gt; model, a very common question I see is how should the roles be prepared so that the &lt;em&gt;new&lt;/em&gt; users can have a list of already created roles to choose from when registering? In the &lt;a href=&#34;https://github.com/RolifyCommunity/rolify&#34;&gt;Rolify documentation&lt;/a&gt;, most (if not all) examples involve implicitely creating roles by adding roles to user in the Rails console:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-ruby&#34; data-lang=&#34;ruby&#34;&gt;&lt;span style=&#34;color:#111&#34;&gt;user&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#00a8c8&#34;&gt;User&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;find&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;
&lt;span style=&#34;color:#111&#34;&gt;user&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;add_role&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;:admin&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;A new &lt;code&gt;admin&lt;/code&gt; role will be created if it does not exist already. But in a fresh application, with no users, a list of existing roles should be available in order to register.&lt;/p&gt;
&lt;p&gt;Answers to this dilemma involve different approaches. I personally prefer creating them when seeding the database:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-ruby&#34; data-lang=&#34;ruby&#34;&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# db/seeds.rb&lt;/span&gt;

&lt;span style=&#34;color:#00a8c8&#34;&gt;Role&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;create!&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;name&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;admin&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;
&lt;span style=&#34;color:#00a8c8&#34;&gt;Role&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;create!&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;name&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;doctor&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;
&lt;span style=&#34;color:#00a8c8&#34;&gt;Role&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;create!&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;name&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;nurse&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
    </item>
    
    <item>
      <title>Select2 With Simple Form in Rails</title>
      <link>https://aalvrz.me/posts/select2-with-simple-form-in-rails/</link>
      <pubDate>Mon, 14 Aug 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/select2-with-simple-form-in-rails/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://select2.github.io/&#34;&gt;Select2&lt;/a&gt; is a great JQuery plugin that customizes your select boxes to give a better user interface and experience.&lt;/p&gt;
&lt;p&gt;Recently while working on a Rails project, I was experiencing some problems when using Select2 and &lt;a href=&#34;https://github.com/plataformatec/simple_form&#34;&gt;Simple Form&lt;/a&gt; in my view.&lt;/p&gt;
&lt;p&gt;In the view, I want to use Select2 to search for people in a &lt;code&gt;Person&lt;/code&gt; table in the application&#39;s database. Select2 should use AJAX to hit a controller&#39;s action that performs the search. The user can then select one of the results found and it will be added to the field as a token (this is a multiple select field).&lt;/p&gt;
&lt;p&gt;The controller action looks something like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-ruby&#34; data-lang=&#34;ruby&#34;&gt;&lt;span style=&#34;color:#00a8c8&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#75af00&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#75af00&#34;&gt;search&lt;/span&gt;
  &lt;span style=&#34;color:#111&#34;&gt;@people&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#00a8c8&#34;&gt;Person&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;all&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;where&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;name LIKE ? OR last_name LIKE ?&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt;
    &lt;span style=&#34;color:#d88200&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;%&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;#{&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;params&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;[&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;:q&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;]&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;%&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;%&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;#{&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;params&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;[&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;:q&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;]&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;%&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;

  &lt;span style=&#34;color:#111&#34;&gt;respond_to&lt;/span&gt; &lt;span style=&#34;color:#00a8c8&#34;&gt;do&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;|&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;format&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;|&lt;/span&gt;
    &lt;span style=&#34;color:#111&#34;&gt;format&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;json&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;{&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;render&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;json&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;@people&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;map&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;{&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;|&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;p&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;|&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;{&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;id&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;p&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;id&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;full_name&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;p&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;full_name&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;}&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;}&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;}&lt;/span&gt;
  &lt;span style=&#34;color:#00a8c8&#34;&gt;end&lt;/span&gt;
&lt;span style=&#34;color:#00a8c8&#34;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
    </item>
    
    <item>
      <title>An Introduction to Game States in Love2D</title>
      <link>https://aalvrz.me/posts/an-introduction-to-game-states-in-love2d/</link>
      <pubDate>Thu, 27 Jul 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/an-introduction-to-game-states-in-love2d/</guid>
      <description>&lt;p&gt;After going through countless blog and video tutorials on getting started with Love2D, I found it sad that most people would not take the approach of implementing &lt;strong&gt;game states&lt;/strong&gt; right from the start, or would try to mimick this functionality in a &amp;ldquo;dirty&amp;rdquo; way.&lt;/p&gt;
&lt;p&gt;After lots of time of reading many forum posts and library documentations. I found a way to implement game states in my games that I am very satisfied with.&lt;/p&gt;
&lt;p&gt;In this post I will go over how to implement game states and some of the most common game states seen in games, in such a way that your code is remains organized and neat.&lt;/p&gt;
&lt;h2 id=&#34;game-states-with-statefullua&#34;&gt;Game States With Stateful.lua&lt;/h2&gt;
&lt;p&gt;We will be using a simple but great Lua library called &lt;a href=&#34;https://github.com/kikito/stateful.lua&#34;&gt;Stateful&lt;/a&gt;, made by &lt;a href=&#34;https://github.com/kikito&#34;&gt;kikito&lt;/a&gt;. This library will allow us to easily implement and work with game states inside our game.&lt;/p&gt;
&lt;p&gt;This library also depends on the &lt;a href=&#34;https://github.com/kikito/middleclass&#34;&gt;Middleclass&lt;/a&gt; library (also by kikito). Middleclass will allow us to construct and develop our game in a OOP (Object Oriented Programing) fashion. If you are familiar with OOP then you will love this approach.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Getting Started With Love2D Basics</title>
      <link>https://aalvrz.me/posts/getting-started-with-love2d-basics/</link>
      <pubDate>Wed, 19 Jul 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/getting-started-with-love2d-basics/</guid>
      <description>&lt;p&gt;I recently started playing around with &lt;a href=&#34;https://love2d.org/&#34;&gt;Love2D&lt;/a&gt; for game development. Although I am completely new to Lua, so far it&#39;s been pretty fun and I really like it.&lt;/p&gt;
&lt;p&gt;I created this post to write down the most important basic concepts that I have encountered so far, so that I can use as quick reference later.&lt;/p&gt;
&lt;h2 id=&#34;setting-up-a-basic-ide&#34;&gt;Setting Up a Basic IDE&lt;/h2&gt;
&lt;p&gt;So far I&#39;ve been using Love2D in Windows. Initially I started using Sublime Text 2 as my editor, but then figured out how to make my Love2D development experience much better using &lt;a href=&#34;https://atom.io/&#34;&gt;Atom&lt;/a&gt; combined with Github for Windows.&lt;/p&gt;
&lt;p&gt;In Atom there is a great package called &lt;a href=&#34;https://github.com/rameshvarun/love-ide&#34;&gt;&lt;strong&gt;love-ide&lt;/strong&gt;&lt;/a&gt; which has many great tools and features for developming with Love.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://aalvrz.me/posts/getting-started-with-love2d-basics/love_ide.jpg&#34; alt=&#34;Love Atom IDE&#34;&gt;&lt;/p&gt;
&lt;p&gt;Some of these features include Lua linting, autocomplete, and being able to run the Love application right from Atom.&lt;/p&gt;
&lt;p&gt;Additionally, we will want to use Window&#39;s console for debugging. To do so, enable these options:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://aalvrz.me/posts/getting-started-with-love2d-basics/love_ide_windows.jpg&#34; alt=&#34;Love in Windows&#34;&gt;&lt;/p&gt;
&lt;h2 id=&#34;working-with-keyboard-keys&#34;&gt;Working With Keyboard Keys&lt;/h2&gt;
&lt;p&gt;We can interact with user input through the keyboard by determining if a certain key has been pressed. This is done like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-lua&#34; data-lang=&#34;lua&#34;&gt;&lt;span style=&#34;color:#00a8c8&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;love.keyboard&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;isDown&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;right&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt; &lt;span style=&#34;color:#00a8c8&#34;&gt;then&lt;/span&gt;
  &lt;span style=&#34;color:#75715e&#34;&gt;-- ...&lt;/span&gt;
&lt;span style=&#34;color:#00a8c8&#34;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The &lt;a href=&#34;https://love2d.org/wiki/love.keyboard.isDown&#34;&gt;&lt;code&gt;love.keyboard.isDown&lt;/code&gt;&lt;/a&gt; function receives a &lt;code&gt;KeyConstant&lt;/code&gt; string argument to indicate which key we want to test for. The complete list can be found &lt;a href=&#34;https://love2d.org/wiki/KeyConstant&#34;&gt;here&lt;/a&gt;. Here are some examples:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;center&#34;&gt;Key string&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;&lt;code&gt;space&lt;/code&gt;&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Space key&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;&lt;code&gt;backspace&lt;/code&gt;&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Backspace key&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;&lt;code&gt;down&lt;/code&gt;&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;Down arrow key&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;</description>
    </item>
    
    <item>
      <title>Extending Device Python Classes From Other ZenPacks</title>
      <link>https://aalvrz.me/posts/extending-device-python-classes-from-other-zenpacks/</link>
      <pubDate>Tue, 27 Jun 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/extending-device-python-classes-from-other-zenpacks/</guid>
      <description>&lt;p&gt;Recently I was struggling with trying to make two custom ZenPacks work together with device objects in the Zenoss database. My issue was that a main ZenPack (which would be installed first) would create a custom class that inherits from &lt;code&gt;Device&lt;/code&gt;. This ZenPack would add a lot of properties and relationships with custom components. Then, a second optional ZenPack could be installed which would extend this same class with an additional property that would work along with a &lt;a href=&#34;https://aalvrz.me/posts/working-with-zenoss-python-data-sources.html&#34;&gt;Python data source&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;zenpack.yaml&lt;/code&gt; file for the first and main ZenPack would look something like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-yaml&#34; data-lang=&#34;yaml&#34;&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# ZenPack1&lt;/span&gt;

classes&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;
  SpecialServer&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;
    base&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;[&lt;/span&gt;zenpacklib.Device&lt;span style=&#34;color:#111&#34;&gt;]&lt;/span&gt;
    label&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt; Special Server

  SpecialComponent&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;
    base&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;[&lt;/span&gt;zenpacklib.Component&lt;span style=&#34;color:#111&#34;&gt;]&lt;/span&gt;
    label&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt; Special Component
    properties&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;
      &lt;span style=&#34;color:#75715e&#34;&gt;# ...&lt;/span&gt;

  AmazingComponent&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;
    base&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;[&lt;/span&gt;zenpacklib.Component&lt;span style=&#34;color:#111&#34;&gt;]&lt;/span&gt;
    label&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt; Amazing Component
    properties&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;
      &lt;span style=&#34;color:#75715e&#34;&gt;# ...&lt;/span&gt;

class_relationships&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;
  - SpecialServer &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;MC SpecialComponent
  - SpecialServer &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;MC AmazingComponent
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
    </item>
    
    <item>
      <title>Using Lambdas in Case Statements in Ruby</title>
      <link>https://aalvrz.me/posts/using-lambdas-in-case-statements-in-ruby/</link>
      <pubDate>Mon, 12 Jun 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/using-lambdas-in-case-statements-in-ruby/</guid>
      <description>&lt;p&gt;In a &lt;a href=&#34;http://aalvarez.me/blog/posts/using-objects-and-ranges-with-cases-in-ruby.html&#34;&gt;previous post&lt;/a&gt; I talked about how we could use Ruby ranges inside case statements. This was a very neat way of using case statements that would make our code more readable and less repetitive.&lt;/p&gt;
&lt;p&gt;The other day I was trying to solve the &lt;a href=&#34;http://exercism.io/submissions/03c3c93f23b8420faff3107e2ad18286&#34;&gt;Bob Ruby exercise in Exercism&lt;/a&gt;, and I came up with another very cool way to use case statements: with Lambdas.&lt;/p&gt;
&lt;h2 id=&#34;the-problem&#34;&gt;The Problem&lt;/h2&gt;
&lt;p&gt;The Bob problem is very simple. The program receives some input, and it returns some output based on the contents of the input. A strong indication for using a case statement. From the problem&#39;s README file:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Bob is a lackadaisical teenager. In conversation, his responses are very limited.

Bob answers &#39;Sure.&#39; if you ask him a question.

He answers &#39;Whoa, chill out!&#39; if you yell at him.

He says &#39;Fine. Be that way!&#39; if you address him without actually saying anything.

He answers &#39;Whatever.&#39; to anything else.
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;solutions&#34;&gt;Solutions&lt;/h2&gt;
&lt;p&gt;The test provided by Exercism indicates that we should create a &lt;code&gt;Bob&lt;/code&gt; class with a &lt;code&gt;hey&lt;/code&gt; class method that receives a remark. We could then use a case statement with this remark and evaluate if the remark is a question, yelling, or whatever else needs to be determined according to the instructions. We could create some class methods to determine each of these possibilities:&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Zenoss Custom Notification Actions Using Subscribers</title>
      <link>https://aalvrz.me/posts/zenoss-custom-notification-actions-using-subscribers/</link>
      <pubDate>Wed, 07 Jun 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/zenoss-custom-notification-actions-using-subscribers/</guid>
      <description>&lt;p&gt;In a &lt;a href=&#34;https://aalvrz.me/posts/custom-notification-action-types-in-zenoss.html&#34;&gt;previous post&lt;/a&gt; I talked about how we could create custom notifications actions in Zenoss. Like a &lt;em&gt;SMS&lt;/em&gt; notification, for example. In that post we required a valid cellphone number using a text field in the notification&#39;s content pane, as shown below:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://aalvrz.me/posts/custom-notification-action-types-in-zenoss/sms_action.jpg&#34; alt=&#34;Notification Content&#34;&gt;&lt;/p&gt;
&lt;p&gt;In this post I want to change and improve this by using &lt;em&gt;&lt;strong&gt;subscribers&lt;/strong&gt;&lt;/em&gt; functionality instead. Similar to the e-mail (or pager) notification, which sends an e-mail to all the subscribed users using their e-mail address configured in their user settings. Since there is no SMS mobile number that we can configure in the user settings, we will have to use the &lt;em&gt;Pager&lt;/em&gt; field instead.&lt;/p&gt;
&lt;h2 id=&#34;the-pager-action&#34;&gt;The Pager Action&lt;/h2&gt;
&lt;p&gt;Using Zenoss Core 4&#39;s pager action&#39;s &lt;a href=&#34;https://github.com/aalvrz/zenoss-core-425/blob/master/usr/local/zenoss/Products/ZenModel/actions.py#L449&#34;&gt;source code&lt;/a&gt; as reference is a good starting point, since we are going to use the pager field for SMS.&lt;/p&gt;
&lt;p&gt;We can see that this action class implements a &lt;code&gt;executeOnTarget&lt;/code&gt; method instead of a &lt;code&gt;execute&lt;/code&gt; method we used in the previous post.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Python Functional HTTP Testing With Gabbi</title>
      <link>https://aalvrz.me/posts/python-functional-http-testing-with-gabbi/</link>
      <pubDate>Tue, 06 Jun 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/python-functional-http-testing-with-gabbi/</guid>
      <description>&lt;p&gt;Continuing with my journey in contributing to &lt;a href=&#34;http://gnocchi.xyz/index.html&#34;&gt;Gnocchi&lt;/a&gt;, I have learned of an excellent tool which Gnocchi uses to test its API from a HTTP request approach. The tool is called &lt;a href=&#34;https://github.com/cdent/gabbi&#34;&gt;&lt;strong&gt;Gabbi&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Coming from a Ruby, Rails, and Rspec background, I was very pleased on learning how Gabbi works and how to use it. Gabbi uses YAML to construct the tests that will hit the API endpoints, in a similar way to using Rspec&#39;s DSL when making &lt;a href=&#34;https://github.com/rspec/rspec-rails#request-specs&#34;&gt;request specs&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;For my latest contribution to Gnocchi, I was working on an &lt;a href=&#34;https://github.com/gnocchixyz/gnocchi/issues/12&#34;&gt;issue&lt;/a&gt; where newly created metrics were not being returned in the response from &lt;code&gt;/v1/resource/generic/:id/metric&lt;/code&gt;. After applying the fixes and submitting the patch, it was also necessary to update some of the functional Gabbi tests that belong to this specific use case.&lt;/p&gt;
&lt;p&gt;One of these original tests is shown below:&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Testing JSON API Strong Parameters in Rails</title>
      <link>https://aalvrz.me/posts/testing-json-api-strong-parameters-in-rails/</link>
      <pubDate>Thu, 25 May 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/testing-json-api-strong-parameters-in-rails/</guid>
      <description>&lt;p&gt;Recently I was experiencing a problem with a Rails API where I would update a model with new attributes, and then proceeded to add the new attributes to the model&#39;s factory, and then add the corresponding model and request specs.&lt;/p&gt;
&lt;p&gt;The problem was that I would forget to whitelist the new attributes in the controller. Then running the request specs would not detect the error since I only test against one updated attribute that was whitelisted long ago. This became really annoying since I had no way to know if the new attributes were being whitelisted or not, and my tests weren&#39;t saying anything about it. This problem becomes even more apparent when the list of whitelisted attributes starts becoming very long.&lt;/p&gt;
&lt;p&gt;In an API following the &lt;a href=&#34;http://jsonapi.org/&#34;&gt;JSON API&lt;/a&gt; specification, here is an example of how the strong parameters method would look like:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-ruby&#34; data-lang=&#34;ruby&#34;&gt;&lt;span style=&#34;color:#00a8c8&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#75af00&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#75af00&#34;&gt;thing_params&lt;/span&gt;
  &lt;span style=&#34;color:#111&#34;&gt;params&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;require&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;:data&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;require&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;:attributes&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;permit&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;:color&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;:size&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;:age&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;:name&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt;
      &lt;span style=&#34;color:#d88200&#34;&gt;:owner&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;:origin&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;:location&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;:purpose&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;:price&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;:alive&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;
&lt;span style=&#34;color:#00a8c8&#34;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;As you can see, the list of attributes is getting pretty long. And we &lt;strong&gt;do not&lt;/strong&gt; want to explicitly keep adding more attributes to the test.&lt;/p&gt;
&lt;h2 id=&#34;testing-strong-parameters-in-controller-specs&#34;&gt;Testing Strong Parameters in Controller Specs&lt;/h2&gt;
&lt;p&gt;After the release of Rails 5 I started ditching controller specs in favor of request specs. I like this approach and I think it&#39;s great, but I think it would be too much unecessary work to test that all the necessary attributes are whitelisted, in the request spec. Therefore I proceeded to create very simple controller specs that would test that &lt;strong&gt;all&lt;/strong&gt; attributes of importance are whitelisted in the controller.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Understanding Gnocchi Measures</title>
      <link>https://aalvrz.me/posts/understanding-gnocchi-measures/</link>
      <pubDate>Wed, 24 May 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/understanding-gnocchi-measures/</guid>
      <description>&lt;p&gt;Measures are simple objects that represent the timeseries data. They simply contain a &lt;strong&gt;timestamp&lt;/strong&gt; and a &lt;strong&gt;value&lt;/strong&gt;, and they belong to &lt;a href=&#34;https://aalvrz.me/posts/understanding-gnocchi-metrics.html&#34;&gt;metrics&lt;/a&gt;. You could say that a measure &lt;em&gt;has many&lt;/em&gt; metrics.&lt;/p&gt;
&lt;h2 id=&#34;adding-measures-to-a-metric&#34;&gt;Adding Measures to a Metric&lt;/h2&gt;
&lt;p&gt;Using the REST API, we can easily add measures to a metric:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-http&#34; data-lang=&#34;http&#34;&gt;&lt;span style=&#34;color:#75af00&#34;&gt;POST&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;/v1/metric/511b61a1-8d67-42d5-8add-66d4209a0469/measures&lt;/span&gt; &lt;span style=&#34;color:#00a8c8&#34;&gt;HTTP&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;1.1&lt;/span&gt;
&lt;span style=&#34;color:#111&#34;&gt;Content-Type&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;:&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;application/json&lt;/span&gt;
&lt;span style=&#34;color:#111&#34;&gt;Content-Length&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;:&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;198&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
    </item>
    
    <item>
      <title>Understanding Gnocchi Metrics</title>
      <link>https://aalvrz.me/posts/understanding-gnocchi-metrics/</link>
      <pubDate>Thu, 18 May 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/understanding-gnocchi-metrics/</guid>
      <description>&lt;p&gt;Metrics are one of the main object types in Gnocchi. They are identified by a UUID and they can also be attached to a resource by using a resource name. Metrics store &lt;strong&gt;measures&lt;/strong&gt;, and the way they do this is defined by &lt;strong&gt;archive policies&lt;/strong&gt;. These are concepts that I will cover in future articles.&lt;/p&gt;
&lt;p&gt;Basically, a metric designates any thing that can be measured: the CPU usage of a server, the temperature of a room or the number of bytes sent by a network interface.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;http://gnocchi.xyz/_images/architecture.png&#34; alt=&#34;Gnocchi Architecture&#34;&gt;&lt;/p&gt;
&lt;p&gt;In the Gnocchi architecture, the &lt;strong&gt;storage&lt;/strong&gt; back-end is responsible for storing measures of created metrics. It receives timestamps and values, and pre-computes aggregations according to the defined archive policies.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Testing a Rails API With RSpec</title>
      <link>https://aalvrz.me/posts/testing-a-rails-api-with-rspec/</link>
      <pubDate>Mon, 15 May 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/testing-a-rails-api-with-rspec/</guid>
      <description>&lt;p&gt;As I continue to improve me API testing skills in Rails, I have come to point where I really feel comfortable with all the tools I need to correctly add useful tests to my API. This post explains how I usually test my Rails APIs using RSpec.&lt;/p&gt;
&lt;h2 id=&#34;setting-up-the-necessary-tools&#34;&gt;Setting Up the Necessary Tools&lt;/h2&gt;
&lt;p&gt;In addition to RSpec, there are a few tools that make my testing experience much easier. These are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/thoughtbot/factory_girl_rails&#34;&gt;Factory Girl&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/stympy/faker&#34;&gt;Faker&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/thoughtbot/shoulda-matchers&#34;&gt;Shoulda Matchers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/DatabaseCleaner/database_cleaner&#34;&gt;Database Cleaner&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;After Adding these gems to the Gemfile. I proceed to create a &lt;code&gt;/support&lt;/code&gt; directory under the &lt;code&gt;/spec&lt;/code&gt; directory. This directory will contain the additional configuration of the above tools, as well as some helper definitions that our specs will use.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;/spec/support/shoulda.rb&lt;/strong&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-ruby&#34; data-lang=&#34;ruby&#34;&gt;&lt;span style=&#34;color:#00a8c8&#34;&gt;Shoulda&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;::&lt;/span&gt;&lt;span style=&#34;color:#00a8c8&#34;&gt;Matchers&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;configure&lt;/span&gt; &lt;span style=&#34;color:#00a8c8&#34;&gt;do&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;|&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;config&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;|&lt;/span&gt;
  &lt;span style=&#34;color:#111&#34;&gt;config&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;integrate&lt;/span&gt; &lt;span style=&#34;color:#00a8c8&#34;&gt;do&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;|&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;with&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;|&lt;/span&gt;
    &lt;span style=&#34;color:#75715e&#34;&gt;# Choose a test framework:&lt;/span&gt;
    &lt;span style=&#34;color:#111&#34;&gt;with&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;test_framework&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;:rspec&lt;/span&gt;

    &lt;span style=&#34;color:#75715e&#34;&gt;# Or, choose the following (which implies all of the above):&lt;/span&gt;
    &lt;span style=&#34;color:#111&#34;&gt;with&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;library&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;:rails&lt;/span&gt;
  &lt;span style=&#34;color:#00a8c8&#34;&gt;end&lt;/span&gt;
&lt;span style=&#34;color:#00a8c8&#34;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
    </item>
    
    <item>
      <title>Custom Notification Action Types in Zenoss</title>
      <link>https://aalvrz.me/posts/custom-notification-action-types-in-zenoss/</link>
      <pubDate>Tue, 09 May 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/custom-notification-action-types-in-zenoss/</guid>
      <description>&lt;p&gt;In a &lt;a href=&#34;https://aalvrz.me/posts/triggering-commands-from-events-in-zenoss.html&#34;&gt;previous post&lt;/a&gt; I talked about how we could create &lt;em&gt;command&lt;/em&gt; type notifications to execute shell scripts when a trigger is fired by an event in Zenoss. Also, in a &lt;a href=&#34;https://aalvrz.me/posts/custom-triggers-and-notifications-in-a-zenpack.html&#34;&gt;more recent post&lt;/a&gt; I explained how a ZenPack could automatically create these triggers and notifications when installed by defining them in JSON format.&lt;/p&gt;
&lt;p&gt;In this post I will explain how to create additional custom action types that can be used by notifications for different purposes.&lt;/p&gt;
&lt;h2 id=&#34;zenoss-default-notification-actions&#34;&gt;Zenoss Default Notification Actions&lt;/h2&gt;
&lt;p&gt;By default, Zenoss comes with a built-in notification action types. You can see them when creating a new notification from the user interface:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://aalvrz.me/posts/custom-notification-action-types-in-zenoss/default_notifications.jpg&#34; alt=&#34;Zenoss Default Actions&#34;&gt;&lt;/p&gt;
&lt;p&gt;These action types are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Command&lt;/strong&gt;: Runs an executable script. Discussed in one of my &lt;a href=&#34;https://aalvrz.me/posts/triggering-commands-from-events-in-zenoss.html&#34;&gt;previous posts&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Email&lt;/strong&gt;: Sends an e-mail to a user.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Page&lt;/strong&gt;: Sends a message to a user&#39;s &lt;a href=&#34;https://en.wikipedia.org/wiki/Pager&#34;&gt;pager&lt;/a&gt;, also known as &lt;em&gt;beeper&lt;/em&gt;. Probably safe to say that this is not used by anyone anymore.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Syslog&lt;/strong&gt;: Logs a message to &lt;a href=&#34;https://en.wikipedia.org/wiki/Syslog&#34;&gt;syslog&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SNMP Trap&lt;/strong&gt;: Sends an SNMP trap.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;All these notifications are sent when an event matches a trigger rule.&lt;/p&gt;
&lt;h2 id=&#34;creating-the-new-action&#34;&gt;Creating the New Action&lt;/h2&gt;
&lt;p&gt;Next, we are going to learn how we can create and add a new fully functional custom action to this list, using a ZenPack. For this example, let&#39;s assume that we want to create a new SMS action to send SMS messages. Surely something more modern and useful than a Pager!&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Rails API With Nested Resources</title>
      <link>https://aalvrz.me/posts/rails-api-with-nested-resources/</link>
      <pubDate>Mon, 08 May 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/rails-api-with-nested-resources/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://github.com/nathanvda/cocoon&#34;&gt;Cocoon&lt;/a&gt; is a very popular gem to add nested resources functionality in Rails. It allows you to add or remove &amp;ldquo;mini forms&amp;rdquo; of another model into a main model&#39;s form and create all objects at once when the form is saved.&lt;/p&gt;
&lt;p&gt;I was recently finding myself trying to implement a similar functionality using only Rails 5 API and &lt;a href=&#34;http://jsonapi.org&#34;&gt;JSON API specification&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;As an example, we will try to implement the commonly seen &lt;em&gt;Work Experience&lt;/em&gt; and &lt;em&gt;Educational Background&lt;/em&gt; features seen in sites such as LinkedIn, where the user can add many items for these categories. The user&#39;s profile and all items for those categories (which are separate models) should all be saved at once, once the form is submitted.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://aalvrz.me/posts/rails-api-with-nested-resources/education.jpg&#34; alt=&#34;Education&#34;&gt;&lt;/p&gt;
&lt;h2 id=&#34;accepts-nested-attributes-for&#34;&gt;accepts_nested_attributes_for&lt;/h2&gt;
&lt;p&gt;&lt;a href=&#34;http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html&#34;&gt;&lt;code&gt;accepts_nested_attributes_for&lt;/code&gt; &lt;/a&gt; allows us to save attributes on &lt;strong&gt;associated&lt;/strong&gt; records (work experience, educational background) through a parent record (user). By default nested attribute updating is turned off and you can enable it using the &lt;code&gt;#accepts_nested_attributes_for&lt;/code&gt; class method.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Custom Triggers and Notifications in a ZenPack</title>
      <link>https://aalvrz.me/posts/custom-triggers-and-notifications-in-a-zenpack/</link>
      <pubDate>Thu, 04 May 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/custom-triggers-and-notifications-in-a-zenpack/</guid>
      <description>&lt;p&gt;In a &lt;a href=&#34;https://aalvrz.me/posts/triggering-commands-from-events-in-zenoss.html&#34;&gt;previous post&lt;/a&gt; I talked about how to use &lt;strong&gt;triggers&lt;/strong&gt; and &lt;strong&gt;command notifications&lt;/strong&gt; in Zenoss to trigger custom actions when certain events occur. All of this was done using the Zenoss user interface.&lt;/p&gt;
&lt;p&gt;In this post we will achieve something similar, but from a custom ZenPack. At the end of this post, our custom ZenPack will be able to create new custom triggers and notifications when installed.&lt;/p&gt;
&lt;h2 id=&#34;defining-zenpack-triggers--notifications&#34;&gt;Defining ZenPack Triggers &amp;amp; Notifications&lt;/h2&gt;
&lt;p&gt;Triggers and notifications within a ZenPack are actually defined using JSON. To do so, you must create a file named &lt;code&gt;actions.json&lt;/code&gt; in a directory called &lt;code&gt;zep&lt;/code&gt; (create it if it doesn&#39;t exist), within the ZenPack&#39;s top directory.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;actions.json&lt;/strong&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-json?line_numbers=false&#34; data-lang=&#34;json?line_numbers=false&#34;&gt;{
  &amp;quot;triggers&amp;quot;: [
    {
      &amp;quot;name&amp;quot;: &amp;quot;Critical_death_event&amp;quot;,
      &amp;quot;uuid&amp;quot;: &amp;quot;4c055067-98b7-483e-8f49-2820b4f2f721&amp;quot;,
      &amp;quot;enabled&amp;quot;: false,
      &amp;quot;rule&amp;quot;: {
        &amp;quot;api_version&amp;quot;: 1,
        &amp;quot;type&amp;quot;: 1,
        &amp;quot;source&amp;quot;: &amp;quot;(evt.event_class.startswith(\&amp;quot;/Status/Ping\&amp;quot;)) and (evt.status == 0) and (evt.severity &amp;gt; 2)&amp;quot;
      }
    }
  ],

  &amp;quot;notifications&amp;quot;: [
    {
      &amp;quot;id&amp;quot;: &amp;quot;send_sms_message&amp;quot;,
      &amp;quot;description&amp;quot;: &amp;quot;Send SMS using Twilio&amp;quot;,
      &amp;quot;action&amp;quot;: &amp;quot;command&amp;quot;,
      &amp;quot;guid&amp;quot;: &amp;quot;2606439f-5ef7-40dc-90e4-3f3bee11cfe6&amp;quot;,
      &amp;quot;enabled&amp;quot;: false,
      &amp;quot;action_timeout&amp;quot;: 60,
      &amp;quot;delay_seconds&amp;quot;: 0,
      &amp;quot;repeat_seconds&amp;quot;: 0,
      &amp;quot;send_initial_occurrence&amp;quot;: false,
      &amp;quot;send_clear&amp;quot;: false,
      &amp;quot;body_format&amp;quot;: &amp;quot;echo \&amp;quot;Hello World!\&amp;quot;&amp;quot;,
      &amp;quot;clear_body_format&amp;quot;: &amp;quot;&amp;quot;,
      &amp;quot;subscriptions&amp;quot;: [&amp;quot;4c055067-98b7-483e-8f49-2820b4f2f721&amp;quot;]
    }
  ]
}
&lt;/code&gt;&lt;/pre&gt;</description>
    </item>
    
    <item>
      <title>Working With RRDTool</title>
      <link>https://aalvrz.me/posts/working-with-rrdtool/</link>
      <pubDate>Tue, 02 May 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/working-with-rrdtool/</guid>
      <description>&lt;p&gt;Zenoss makes a lot of use of &lt;a href=&#34;http://oss.oetiker.ch/rrdtool/&#34;&gt;RRDTool&lt;/a&gt; for &lt;a href=&#34;https://aalvrz.me/posts/using-rrdtool-in-zenoss.html&#34;&gt;storing monitored performance data and generating graphs&lt;/a&gt;. In this post I want to go into more detail on the components of RRDTool and how works.&lt;/p&gt;
&lt;h2 id=&#34;round-robin-databases&#34;&gt;Round Robin Databases&lt;/h2&gt;
&lt;p&gt;RRDTool is a program that works with Round Robin databases (hence RRD). This type of database is more geared and limited towards storing &lt;strong&gt;time series&lt;/strong&gt; data.&lt;/p&gt;
&lt;p&gt;Moreover, rrdtool also &lt;strong&gt;doesn&#39;t&lt;/strong&gt; store the data handed to it. Instead, it first &lt;strong&gt;re-samples&lt;/strong&gt; the data and &lt;em&gt;then&lt;/em&gt; stores this re-sampled data. Since rrdtool deals with time series data, it knows that certain data is meant to be stored every certain period of time (i.e 5 minutes). This newly re-sampled data will be the same as the original data, but the stored numbers will be different.&lt;/p&gt;
&lt;p&gt;This means that if for example, we were to store some data every 5 minutes, a data sample that arrives at the &lt;code&gt;03&lt;/code&gt; minute mark cannot go into the database, therefore it has to be re-adjusted into the correct slots. While rrdtool makes this adjustment, it will also change the value, so that this new value still represents the space in the curve.&lt;/p&gt;
&lt;p&gt;In rrdtool, each database table is stored in a separate &lt;code&gt;.rrd&lt;/code&gt; file. This means that one file represents one table.&lt;/p&gt;
&lt;p&gt;We can create a database using the following command:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;rrdtool create ex5.rrd --step=5 DS:input:GAUGE:10:0:1000000 RRA:LAST:0.5:1:603
&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&#34;data-re-sampling-step&#34;&gt;Data Re-sampling: Step&lt;/h3&gt;
&lt;p&gt;One important parameter here is the &lt;code&gt;step&lt;/code&gt; parameter. This means that rrdtool will re-sample all the data that is fed into the database to a 300 second interval. Still, data can be fed as quickly as desired (i.e a lot of data in one second), however the data will be re-sampled to 300 seconds on storage. &lt;strong&gt;This means that it only stores data every 300 seconds&lt;/strong&gt;. Because of this re-sampling, rrdtool will not accept data from the past.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Diving Into OpenStack Gnocchi</title>
      <link>https://aalvrz.me/posts/diving-into-openstack-gnocchi/</link>
      <pubDate>Tue, 25 Apr 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/diving-into-openstack-gnocchi/</guid>
      <description>&lt;p&gt;Gnocchi is a multi-tenant timeseries, metrics and resources database. It provides an HTTP REST interface to create and manipulate the data. It is designed to store metrics at a very large scale while providing access to metrics and resources information and history.&lt;/p&gt;
&lt;p&gt;It is the preferred storage method for metrics in Ceilometer, as of OpenStack Ocata.&lt;/p&gt;
&lt;p&gt;In this post I want to dive into Gnocchi specifics such as its configuration, supported backends, APIs, daemons, and source code.&lt;/p&gt;
&lt;h2 id=&#34;configuration&#34;&gt;Configuration&lt;/h2&gt;
&lt;p&gt;Gnocchi&#39;s configuration is stored in a file called &lt;code&gt;gnocchi.conf&lt;/code&gt;. Ideally, this file would be in &lt;code&gt;~/gnocchi.conf&lt;/code&gt; or &lt;code&gt;/etc/gnocchi/gnocchi.conf&lt;/code&gt;. Let&#39;s take a look at a basic Gnocchi configuration:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-ini&#34; data-lang=&#34;ini&#34;&gt;&lt;span style=&#34;color:#00a8c8&#34;&gt;[DEFAULT]&lt;/span&gt;
&lt;span style=&#34;color:#75af00&#34;&gt;debug&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;true&lt;/span&gt;
&lt;span style=&#34;color:#75af00&#34;&gt;verbose&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;true&lt;/span&gt;

&lt;span style=&#34;color:#00a8c8&#34;&gt;[api]&lt;/span&gt;
&lt;span style=&#34;color:#75af00&#34;&gt;workers&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;1&lt;/span&gt;

&lt;span style=&#34;color:#00a8c8&#34;&gt;[database]&lt;/span&gt;
&lt;span style=&#34;color:#75af00&#34;&gt;backend&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;sqlalchemy&lt;/span&gt;

&lt;span style=&#34;color:#00a8c8&#34;&gt;[indexer]&lt;/span&gt;
&lt;span style=&#34;color:#75af00&#34;&gt;url&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;postgresql://gnocchi:gnocchi@127.0.0.1/gnocchi&lt;/span&gt;

&lt;span style=&#34;color:#00a8c8&#34;&gt;[storage]&lt;/span&gt;
&lt;span style=&#34;color:#75af00&#34;&gt;coordination_url&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;file:///home/ubuntu/gn/locks&lt;/span&gt;
&lt;span style=&#34;color:#75af00&#34;&gt;driver&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;file&lt;/span&gt;
&lt;span style=&#34;color:#75af00&#34;&gt;file_basepath&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;/home/ubuntu/gn&lt;/span&gt;

&lt;span style=&#34;color:#00a8c8&#34;&gt;[cors]&lt;/span&gt;
&lt;span style=&#34;color:#75af00&#34;&gt;allowed_origin&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;*&lt;/span&gt;
&lt;span style=&#34;color:#75af00&#34;&gt;allow_credentials&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The configuration above sets up Gnocchi to use Postgresql as the indexer, and use the file system for storage. Additionally it sets up CORS so that requests from any origin are allowed. You will want to configure CORS in a more secure manner when deploying to a production environment.&lt;/p&gt;
&lt;h3 id=&#34;database-setup&#34;&gt;Database Setup&lt;/h3&gt;
&lt;p&gt;For this example, we are going to use &lt;a href=&#34;www.c9.io&#34;&gt;Cloud 9&lt;/a&gt; as our environment, and Postgresql as the database. This means that we need to first setup the database before we start using Gnocchi.&lt;/p&gt;
&lt;p&gt;Make sure the Postgresql service is running:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;sudo service postgresql start
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We can enter the Postgresql command line using:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;sudo sudo -u postgres psql
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now let&#39;s create a new Postgresql user:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;CREATE USER gnocchi SUPERUSER PASSWORD &#39;gnocchi&#39;;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then create the database:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;CREATE DATABASE gnocchi WITH TEMPLATE = template0 ENCODING = &#39;UNICODE&#39;;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;When the database is finally set up correctly and the configuration file is in place, we can initialize the indexer and storage:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;gnocchi-upgrade
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You should see the following output logs:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;2017-05-17 05:28:50.917 3895 INFO gnocchi.cli [-] Upgrading indexer &amp;lt;gnocchi.indexer.sqlalchemy.SQLAlchemyIndexer object at 0x7ff76cff6190&amp;gt;
2017-05-17 05:28:50.982 3895 INFO alembic.runtime.migration [-] Context impl PostgresqlImpl.
2017-05-17 05:28:50.982 3895 INFO alembic.runtime.migration [-] Will assume transactional DDL.
2017-05-17 05:28:51.011 3895 INFO alembic.runtime.migration [-] Context impl PostgresqlImpl.
2017-05-17 05:28:51.011 3895 INFO alembic.runtime.migration [-] Will assume transactional DDL.
2017-05-17 05:28:51.154 3895 INFO gnocchi.cli [-] Upgrading storage &amp;lt;gnocchi.storage.file.FileStorage object at 0x7ff7688f9710&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;gnocchi-rest-api&#34;&gt;Gnocchi REST API&lt;/h2&gt;
&lt;p&gt;Gnocchi&#39;s REST API is based on &lt;a href=&#34;http://www.pecanpy.org/index.html&#34;&gt;Pecan&lt;/a&gt;, a very lightweight Python web framework that provides object-dispatch style routing. We can confirm this in Gnocchi&#39;s &lt;code&gt;rest/__init__.py&lt;/code&gt; file:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;pecan&lt;/span&gt;
&lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;pecan&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;rest&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;metrics&#34;&gt;Metrics&lt;/h3&gt;
&lt;p&gt;Gnocchi provides an object type that is called metric. A metric designates any thing that can be measured: the CPU usage of a server, the temperature of a room or the number of bytes sent by a network interface.&lt;/p&gt;
&lt;p&gt;A metric only has a few properties: a UUID to identify it, a name, the archive policy that will be used to store and aggregate the measures.&lt;/p&gt;
&lt;p&gt;Farther down the code in &lt;code&gt;rest/__init__.py&lt;/code&gt;, we can find a metric controller which inherits from a Pecan REST controller:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;color:#00a8c8&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#75af00&#34;&gt;MetricController&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;rest&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;RestController&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;
    &lt;span style=&#34;color:#111&#34;&gt;_custom_actions&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;{&lt;/span&gt;
        &lt;span style=&#34;color:#d88200&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;measures&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;[&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;POST&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;GET&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;]&lt;/span&gt;
    &lt;span style=&#34;color:#111&#34;&gt;}&lt;/span&gt;

    &lt;span style=&#34;color:#00a8c8&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;__init__&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;self&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;metric&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;
        &lt;span style=&#34;color:#111&#34;&gt;self&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;metric&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;metric&lt;/span&gt;
        &lt;span style=&#34;color:#111&#34;&gt;mgr&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;extension&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;ExtensionManager&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;namespace&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;gnocchi.aggregates&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt;
                                         &lt;span style=&#34;color:#111&#34;&gt;invoke_on_load&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;True&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;
        &lt;span style=&#34;color:#111&#34;&gt;self&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;custom_agg&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;dict&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;x&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;name&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;x&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;obj&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt; &lt;span style=&#34;color:#00a8c8&#34;&gt;for&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;x&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;mgr&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;

    &lt;span style=&#34;color:#00a8c8&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#75af00&#34;&gt;enforce_metric&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;self&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;rule&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;
        &lt;span style=&#34;color:#111&#34;&gt;enforce&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;rule&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;json&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;to_primitive&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;self&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;metric&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;

    &lt;span style=&#34;color:#75af00&#34;&gt;@pecan.expose&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;json&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;
    &lt;span style=&#34;color:#00a8c8&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#75af00&#34;&gt;get_all&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;self&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;
        &lt;span style=&#34;color:#111&#34;&gt;self&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;enforce_metric&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;get metric&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;
        &lt;span style=&#34;color:#00a8c8&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;self&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;metric&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;From the &lt;a href=&#34;http://pecan.readthedocs.io/en/latest/routing.html&#34;&gt;Pecan documentation&lt;/a&gt;, we can learn that Pecan uses a routing strategy known as object-dispatch to map an HTTP request to a controller, and then the method to call. Object-dispatch begins by splitting the path into a list of components and then walking an object path, starting at the root controller.&lt;/p&gt;
&lt;p&gt;We can tell Pecan which methods in a class are publically-visible via &lt;code&gt;expose()&lt;/code&gt;. If a method is not decorated with &lt;code&gt;expose()&lt;/code&gt;, Pecan will never route a request to it. In the example above, the &lt;code&gt;get_all()&lt;/code&gt; method is exposed to Pecan. Additionally, it makes use of Pecan&#39;s built-in support for a special JSON renderer, which translates template namespaces into rendered JSON text. Meaning that the returned content will be rendered as JSON.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Understanding oslo_config in OpenStack</title>
      <link>https://aalvrz.me/posts/understanding-oslo_config-in-openstack/</link>
      <pubDate>Tue, 18 Apr 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/understanding-oslo_config-in-openstack/</guid>
      <description>&lt;p&gt;The OpenStack &lt;a href=&#34;https://wiki.openstack.org/wiki/Oslo&#34;&gt;Oslo&lt;/a&gt; library provides a set of Python libraries containing code shared by different OpenStack projects. This helps the many different OpenStack projects to follow a certain standard and convention when being developed.&lt;/p&gt;
&lt;p&gt;In this post I want to go over &lt;a href=&#34;https://wiki.openstack.org/wiki/Oslo/Config&#34;&gt;oslo_config&lt;/a&gt;. This library helps with parsing of &lt;strong&gt;options&lt;/strong&gt; found in configuration files or command line arguments.&lt;/p&gt;
&lt;h2 id=&#34;understanding-options&#34;&gt;Understanding Options&lt;/h2&gt;
&lt;p&gt;An option is defined using the &lt;code&gt;Opt&lt;/code&gt; class or one of its sub-classes, from the &lt;code&gt;cfg&lt;/code&gt; module:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;oslo_config&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;cfg&lt;/span&gt;

&lt;span style=&#34;color:#111&#34;&gt;common_opts&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;[&lt;/span&gt;
    &lt;span style=&#34;color:#111&#34;&gt;cfg&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;StrOpt&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;bind_host&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt;
               &lt;span style=&#34;color:#111&#34;&gt;default&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;0.0.0.0&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt;
               &lt;span style=&#34;color:#111&#34;&gt;help&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;IP address to listen on.&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt;
    &lt;span style=&#34;color:#111&#34;&gt;cfg&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;Opt&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;bind_port&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt;
            &lt;span style=&#34;color:#111&#34;&gt;type&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;PortType&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt;
            &lt;span style=&#34;color:#111&#34;&gt;default&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;9292&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt;
            &lt;span style=&#34;color:#111&#34;&gt;help&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;Port number to listen on.&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;
&lt;span style=&#34;color:#111&#34;&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In the example above we can see that we are using &lt;code&gt;Opt&lt;/code&gt; and &lt;code&gt;StrOpt&lt;/code&gt;, one of its sub-classes. You might notice that the second option&#39;s constructor has a &lt;code&gt;type=PortType&lt;/code&gt; argument. This argument is a callable object that takes a string and either returns a value of that particular type, or raises &lt;code&gt;ValueError&lt;/code&gt; if the value cannot be converted. The different types available can be found in the &lt;code&gt;types&lt;/code&gt; module:&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Tech and Open Source Chinese Vocabulary</title>
      <link>https://aalvrz.me/posts/tech-and-open-source-chinese-vocabulary/</link>
      <pubDate>Mon, 17 Apr 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/tech-and-open-source-chinese-vocabulary/</guid>
      <description>The following is my personal curated list of Chinese terms (in Traditional Chinese) and vocabulary used in web development, programming, technology and open source.
   Chinese Word Pinyin Definition     修復 xiū fù Repair, fix (bug)   發版 fā bǎn To release a version   報錯 baò cuò Error report/message   組件 zǔ jiàn Component   版本 bǎn běn Version   更新 gèng xīn To update/upgrade   顯示 xiǎn shì Show, display   表格 biaǒ gé Form, table   按鈕 àn niú Button, to press a button   重新 chóng xīn Retry (verb)   項目 xiàng mù Project   需求 xū qiú Request   代碼 dài mǎ Code   源碼 yuán mǎ Source code   固定 gù dìng Fixed, regular   內容 nèi róng Content   輸入 shū rù Input, to input   屬性 shǔ xìng attribute, property   路由 lù yóu routing   參考 cān kǎo Consult, refer to, reference   標題 biaō tí title, heading   一致 yī zhì consistent, identical   默認 mò rèn default   里程碑 lǐ chéng bēi milestone   圖標 tú biaō icon   接口 jiē koǔ interface, port   操作系統 Cāozuò xìtǒng operating system   支持 zhī chí support   佈局 bù jú layout    </description>
    </item>
    
    <item>
      <title>Debian Package Versioning</title>
      <link>https://aalvrz.me/posts/debian-package-versioning/</link>
      <pubDate>Thu, 13 Apr 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/debian-package-versioning/</guid>
      <description>&lt;p&gt;In a previous post I talked about &lt;a href=&#34;https://aalvrz.me/posts/managing-debian-package-dependencies.html&#34;&gt;managing Debian package dependencies&lt;/a&gt;. However I did not go into detail about the structure the versioning of packages must have.&lt;/p&gt;
&lt;p&gt;To recap, let&#39;s see how we can specify a specific package version of a dependency that our package needs:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Depends: erlang (&amp;gt;= 1.2)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;In the example above, the required version for erlang is simply &lt;code&gt;1.2&lt;/code&gt; or greater. A package&#39;s version format however, can be a bit more complex than this.&lt;/p&gt;
&lt;h2 id=&#34;version-format-and-components&#34;&gt;Version Format and Components&lt;/h2&gt;
&lt;p&gt;The official format of a Debian package&#39;s version is:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;[epoch:]upstream_version[-debian_revision]
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Let&#39;s go into detail about each of the components in that format.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Understanding Ceilometer Publishers</title>
      <link>https://aalvrz.me/posts/understanding-ceilometer-publishers/</link>
      <pubDate>Tue, 11 Apr 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/understanding-ceilometer-publishers/</guid>
      <description>&lt;p&gt;Continuing with my study of the Ceilometer pipeline, this post now covers Ceilometer &lt;strong&gt;publishers&lt;/strong&gt;. Publishers are components that make it possible to save the data into a persistent storage through the message bus, or to send it to one or more external consumers.&lt;/p&gt;
&lt;p&gt;Publishers are specified in the &lt;code&gt;publishers&lt;/code&gt; section for each pipeline that is defined in the &lt;code&gt;pipeline.yaml&lt;/code&gt; and the &lt;code&gt;event_pipeline.yaml&lt;/code&gt; files.&lt;/p&gt;
&lt;p&gt;Many different publishers are available. The following are the most common and important publishers:&lt;/p&gt;
&lt;h3 id=&#34;gnocchi&#34;&gt;Gnocchi&lt;/h3&gt;
&lt;p&gt;&lt;img src=&#34;http://gnocchi.xyz/_images/gnocchi-logo.jpg&#34; alt=&#34;Gnocchi Logo&#34;&gt;&lt;/p&gt;
&lt;p&gt;Gnocchi is a multi-tenant timeseries, metrics and resources database. It provides an HTTP REST interface to create and manipulate the data. It is designed to store metrics at a very large scale while providing access to metrics and resources information and history.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Reworking Ace&#39;s HAML Syntax Highlighting</title>
      <link>https://aalvrz.me/posts/reworking-ace-s-haml-syntax-highlighting/</link>
      <pubDate>Mon, 10 Apr 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/reworking-ace-s-haml-syntax-highlighting/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://github.com/ajaxorg/ace&#34;&gt;Ace&lt;/a&gt; is a great web text editor and the default editor for &lt;a href=&#34;https://c9.io&#34;&gt;Cloud 9 IDE&lt;/a&gt;. I have been using it for many years without any complaints at all. However I was not very satisfied with the HAML syntax highlighting, which seemed to have some problems caused by indentation when highlighting some tokens. Additionally, it didn&#39;t support correct highlighting of some HAML stuff such as HAML comments (which begin with &lt;code&gt;-#&lt;/code&gt;) or block comments.&lt;/p&gt;
&lt;p&gt;This is how Ace&#39;s HAML syntax highlighting issues look like:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://aalvrz.me/posts/reworking-ace-s-haml-syntax-highlighting/haml_bad_highlighting.jpg&#34; alt=&#34;HAML Highlighting Issues&#34;&gt;&lt;/p&gt;
&lt;p&gt;I proceeded to study Ace&#39;s logic for syntax highlighting. It consists basically on a lexer that reads the input through different regular expressions and proceeds to different stages depending on the regular expression caught. Basically, a &lt;a href=&#34;https://en.wikipedia.org/wiki/Finite-state_machine&#34;&gt;state machine&lt;/a&gt;. The source where this happens is found in &lt;a href=&#34;https://github.com/ajaxorg/ace/blob/master/lib/ace/mode/haml_highlight_rules.js&#34;&gt;&lt;code&gt;lib/ace/mode/haml_highlight_rules.js&lt;/code&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;defining-states&#34;&gt;Defining States&lt;/h2&gt;
&lt;p&gt;A few states have to be defined to represent where the lexer currently &amp;ldquo;stands&amp;rdquo; in regards to the code. For example, entering a multi-block comment could represent entering a new state, since everything parsed in this state would belong to this block comment until the block ends, this will also mean another change of state.&lt;/p&gt;
&lt;p&gt;In Ace, all syntax highlighting lexers must begin with a &lt;code&gt;start&lt;/code&gt; state. From this state we can switch to other defined states. The example below shows how we begin from the &lt;code&gt;start&lt;/code&gt; state and can jump to a comment block state when the code matches a regular expression that represents this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;color:#00a8c8&#34;&gt;this&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#75af00&#34;&gt;$rules&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;{&lt;/span&gt;
    &lt;span style=&#34;color:#d88200&#34;&gt;&amp;#34;start&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;:&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;[&lt;/span&gt;
        &lt;span style=&#34;color:#111&#34;&gt;{&lt;/span&gt;
            &lt;span style=&#34;color:#75af00&#34;&gt;token&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;:&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;&amp;#34;comment.block&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#75715e&#34;&gt;// multiline HTML comment
&lt;/span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;&lt;/span&gt;            &lt;span style=&#34;color:#75af00&#34;&gt;regex&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;:&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;/^\/$/&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt;
            &lt;span style=&#34;color:#75af00&#34;&gt;next&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;:&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;&amp;#34;comment&amp;#34;&lt;/span&gt;
        &lt;span style=&#34;color:#111&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt;
        &lt;span style=&#34;color:#111&#34;&gt;{&lt;/span&gt;
            &lt;span style=&#34;color:#75af00&#34;&gt;token&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;:&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;&amp;#34;comment.block&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#75715e&#34;&gt;// multiline HAML comment
&lt;/span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;&lt;/span&gt;            &lt;span style=&#34;color:#75af00&#34;&gt;regex&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;:&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;/^\-#$/&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt;
            &lt;span style=&#34;color:#75af00&#34;&gt;next&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;:&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;&amp;#34;comment&amp;#34;&lt;/span&gt;
&lt;span style=&#34;color:#111&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt;

&lt;span style=&#34;color:#75715e&#34;&gt;/* ... */&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Notice that we define 2 different comment types, since HAML &lt;a href=&#34;http://haml.info/docs/yardoc/file.REFERENCE.html&#34;&gt;supports&lt;/a&gt; HAML (not rendered in HTML) and HTML (rendered in HTML) comments. Both of these different regular expressions will make the lexer parse them as &lt;code&gt;comment.block&lt;/code&gt; &lt;strong&gt;tokens&lt;/strong&gt;, and will also make the lexer jump to a &lt;code&gt;comment&lt;/code&gt; state, denoted by the &lt;code&gt;next&lt;/code&gt; keyword.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Understanding Ceilometer Transformers</title>
      <link>https://aalvrz.me/posts/understanding-ceilometer-transformers/</link>
      <pubDate>Fri, 07 Apr 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/understanding-ceilometer-transformers/</guid>
      <description>&lt;p&gt;Ceilometer &lt;strong&gt;transformers&lt;/strong&gt; are part of the Ceilometer &lt;strong&gt;pipeline&lt;/strong&gt;, which is the mechanism by which data is processed. In Ceilometer there is a pipeline for &lt;strong&gt;samples&lt;/strong&gt; and a pipeline for &lt;strong&gt;events&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Configurations for these pipelines can be found in &lt;code&gt;/etc/ceilometer/pipeline.yaml&lt;/code&gt; and &lt;code&gt;/etc/ceilometer/event_pipeline.yaml&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Transformers are responsible for mutating data points and passing them to publishers that will send the data to external systems.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://docs.openstack.org/developer/ceilometer/_images/3-Pipeline.png&#34; alt=&#34;Ceilometer Pipeline&#34;&gt;&lt;/p&gt;
&lt;p&gt;Different types of transformers exist to mutate different types of data. The following is a table containing all the available transformer types:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;left&#34;&gt;Name of transformer&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Reference name for configuration&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Accumulator&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;accumulator&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Aggregator&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;aggregator&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Arithmetic&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;arithmetic&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Rate of change&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;rate_of_change&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Unit conversion&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;unit_conversion&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;left&#34;&gt;Delta&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;delta&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Let&#39;s take a more detailed look into the accumulator transformer.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Ceilometer and OpenStack Notifications</title>
      <link>https://aalvrz.me/posts/ceilometer-and-openstack-notifications/</link>
      <pubDate>Thu, 06 Apr 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/ceilometer-and-openstack-notifications/</guid>
      <description>&lt;p&gt;Ceilometer has different mechanisms to collect data from OpenStack. One of these mechanisms, are &lt;strong&gt;notifications&lt;/strong&gt;, which will be explained in this post.&lt;/p&gt;
&lt;h2 id=&#34;openstack-notifications&#34;&gt;OpenStack Notifications&lt;/h2&gt;
&lt;p&gt;All OpenStack services (such as Nova Compute, Neutron, etc.) send notifications about executed operations or the state of the system. Many of these notifications carry information that can be metered such as &lt;strong&gt;CPU time&lt;/strong&gt; of a virtual machine instance created by the compute service.&lt;/p&gt;
&lt;p&gt;OpenStack services send these notifications through an AMQP message queue. However, not all these notifications are consumed by the Telemetry service, as the intention is only to capture the billable events and notifications that can be used for monitoring or profiling purposes. The notification agent filters by the &lt;strong&gt;event type&lt;/strong&gt;. Each notification message contains the event type.&lt;/p&gt;
&lt;p&gt;Here is a table with a few examples:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;center&#34;&gt;OpenStack Service&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;Event types&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;OpenStack Compute&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;&lt;code&gt;scheduler.run_instance.scheduled&lt;/code&gt;, &lt;code&gt;scheduler.select_destinations&lt;/code&gt;, &lt;code&gt;compute.instance.*&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;OpenStack Image&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;&lt;code&gt;image.update&lt;/code&gt;, &lt;code&gt;image.upload&lt;/code&gt;,  &lt;code&gt;image.delete&lt;/code&gt;, &lt;code&gt;image.send&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;In Ceilometer, the &lt;strong&gt;notification agent&lt;/strong&gt; is reponsible for consuming these notifications from the AMQP message bus, and then transforming them into &lt;strong&gt;events&lt;/strong&gt; and &lt;strong&gt;samples&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://docs.openstack.org/developer/ceilometer/_images/2-1-collection-notification.png&#34; alt=&#34;Notifications Collection&#34;&gt;&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Using Rails With Webpack in Cloud 9</title>
      <link>https://aalvrz.me/posts/using-rails-with-webpack-in-cloud-9/</link>
      <pubDate>Mon, 03 Apr 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/using-rails-with-webpack-in-cloud-9/</guid>
      <description>&lt;p&gt;The &lt;a href=&#34;https://github.com/rails/webpacker&#34;&gt;rails/webpacker&lt;/a&gt; project allows integration of &lt;a href=&#34;https://webpack.github.io/&#34;&gt;Webpack&lt;/a&gt; with a Rails application. However, setting this up in a &lt;a href=&#34;https://c9.io&#34;&gt;Cloud 9&lt;/a&gt; development environment needs a few tweaks to be able to work correctly. This post explains how to achieve this.&lt;/p&gt;
&lt;h2 id=&#34;creating-the-application&#34;&gt;Creating the Application&lt;/h2&gt;
&lt;p&gt;We will first create a regular Rails application and then use the webpacker gem to install Webpack.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;rails new webpack-app
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Add the gem to &lt;code&gt;Gemfile&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-ruby&#34; data-lang=&#34;ruby&#34;&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# Gemfile&lt;/span&gt;

&lt;span style=&#34;color:#111&#34;&gt;gem&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;webpacker&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;github&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;rails/webpacker&amp;#39;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Install Webpacker&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;rails webpacker:install
&lt;/code&gt;&lt;/pre&gt;</description>
    </item>
    
    <item>
      <title>Using Objects and Ranges With Cases in Ruby</title>
      <link>https://aalvrz.me/posts/using-objects-and-ranges-with-cases-in-ruby/</link>
      <pubDate>Wed, 29 Mar 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/using-objects-and-ranges-with-cases-in-ruby/</guid>
      <description>&lt;p&gt;Ruby&#39;s &lt;a href=&#34;http://www.techotopia.com/index.php/The_Ruby_case_Statement&#34;&gt;&lt;code&gt;case&lt;/code&gt; statement&lt;/a&gt; provides some nice functionality to be used with objects and ranges. I was recently developing a small application in Ruby on Rails using blood test data where I had to check if a certain test item (i.e. HDL Cholesterol) value belonged to a certain range. I did not want to use a bunch of &lt;code&gt;if&lt;/code&gt; statements and I actually found a pretty neat way to implement using the Ruby &lt;code&gt;case&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;In my application I have a Rails model called &lt;code&gt;Entry&lt;/code&gt; which represents a blood test result with a lot of field data such as blood glucose level, blood pressure level, etc. etc. I want to display this data in the view using Bootstrap 3&#39;s nice &lt;a href=&#34;http://getbootstrap.com/components/#progress&#34;&gt;progress bars&lt;/a&gt; and I want the progress bar&#39;s contextual class to be changed and determined by the range in which this data point sits in.&lt;/p&gt;
&lt;p&gt;If we take &lt;a href=&#34;https://en.wikipedia.org/wiki/Cholesterol&#34;&gt;total cholesterol&lt;/a&gt; as an example, a quick Google search indicates that an ideal value would be less than 200 mg/dL, a high value (not good) would be between 200-239 mg/dL, and a very high value (definitely not good) would be above 240 mg/dL.&lt;/p&gt;
&lt;p&gt;To implement this, I created a &lt;code&gt;Recommendations&lt;/code&gt; module under the &lt;code&gt;/models&lt;/code&gt; directory. All classes belonging to this module will have different ranges to represent what I explained above. This is what the model directory tree looks like:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;app/models/
├── application_record.rb
├── concerns
├── entry.rb
├── recommendations
│   ├── blood_glucose.rb
│   ├── diastolic_pressure.rb
│   ├── hdl.rb
│   ├── ldl.rb
│   ├── systolic_pressure.rb
│   └── total_cholesterol.rb
└── user.rb
&lt;/code&gt;&lt;/pre&gt;</description>
    </item>
    
    <item>
      <title>Setting Up an OpenStack Dev Environment</title>
      <link>https://aalvrz.me/posts/setting-up-an-openstack-dev-environment/</link>
      <pubDate>Wed, 22 Mar 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/setting-up-an-openstack-dev-environment/</guid>
      <description>&lt;p&gt;Before beginning to &lt;a href=&#34;https://aalvrz.me/posts/getting-started-on-contributing-to-openstack.html&#34;&gt;contribute to OpenStack&lt;/a&gt;, it is necessary that we setup an ideal development environment for a smoother workflow.&lt;/p&gt;
&lt;p&gt;In this post I will cover how to setup a Devstack development environment in a &lt;strong&gt;Ubuntu 16.04&lt;/strong&gt; virtual machine using &lt;a href=&#34;http://www.vmware.com/&#34;&gt;VMware Player&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;setting-up-the-ubuntu-virtual-machine&#34;&gt;Setting Up the Ubuntu Virtual Machine&lt;/h2&gt;
&lt;p&gt;Make sure you have &lt;a href=&#34;http://download.cnet.com/VMware-Player/3000-2094_4-10470784.html&#34;&gt;VMware Player&lt;/a&gt; installed in your system. Then we need to choose an appropriate Ubuntu ISO image for our virtual machine. In my case I am using a &lt;a href=&#34;http://releases.ubuntu.com/xenial/&#34;&gt;Ubuntu Desktop 16.04.2 LTS (Xenial Xerus)&lt;/a&gt; for &lt;strong&gt;32-bit PC i836&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;In VMware Player, create a new virtual machine using the wizard. Assign your preferred amount of memory and storage space. Now start the machine, and select the Ubuntu &lt;code&gt;.iso&lt;/code&gt; image file when prompted. Proceed with the installation and select the &lt;em&gt;Erase Disk and Install Ubuntu&lt;/em&gt; option when prompted.&lt;/p&gt;
&lt;p&gt;~&amp;gt; I tried using &lt;a href=&#34;https://www.virtualbox.org/&#34;&gt;VirtualBox&lt;/a&gt; for virtualization but I could not successfully install Devstack with it. Probably due to issues on using the correct network adapter. I also tried using Ubuntu 14.04 without success as well. This is why I recommend &lt;strong&gt;Ubuntu 16.04&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Once the installation is finished, restart the virtual machine.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Overriding Default Zenoss Pages</title>
      <link>https://aalvrz.me/posts/overriding-default-zenoss-pages/</link>
      <pubDate>Fri, 17 Mar 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/overriding-default-zenoss-pages/</guid>
      <description>&lt;p&gt;While testing the &lt;a href=&#34;https://github.com/zenoss/ZenPacks.zenoss.Layer2&#34;&gt;Layer 2 ZenPack&lt;/a&gt;, I noticed that the network map provided by the ZenPack was placed in the same page of the old default Zenoss&#39;s network map, replacing the latter which was made using Flash. After the ZenPack is installed, when you click on the &lt;em&gt;Network Map&lt;/em&gt; secondary link in the Infrastructure page, you will get the new map instead.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://aalvrz.me/posts/overriding-default-zenoss-pages/map_link.jpg&#34; alt=&#34;Network Map link&#34;&gt;&lt;/p&gt;
&lt;p&gt;This seemed pretty nice, and I was curious how they achieved this, so I started browsing around the source code. It turns out that this overriding is done in a file called &lt;code&gt;overrides.zcml&lt;/code&gt;, which is placed in the ZenPack&#39;s top directory.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Getting Started on Contributing to OpenStack</title>
      <link>https://aalvrz.me/posts/getting-started-on-contributing-to-openstack/</link>
      <pubDate>Tue, 14 Mar 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/getting-started-on-contributing-to-openstack/</guid>
      <description>&lt;p&gt;&lt;img src=&#34;http://seeklogo.com/images/O/openstack-logo-4A37C6FB5B-seeklogo.com.png&#34; alt=&#34;OpenStack&#34;&gt;&lt;/p&gt;
&lt;p&gt;I have started to become interested in contributing to the &lt;a href=&#34;https://www.openstack.org/&#34;&gt;OpenStack&lt;/a&gt; project. Starting to contribute to such a massive project can seem like a daunting task, and it is. It is only by arming yourself with the proper tools and knowledge prior to contributing, that you will have a smoother process. I created this blog post to smooth that process.&lt;/p&gt;
&lt;h2 id=&#34;picking-a-project&#34;&gt;Picking a Project&lt;/h2&gt;
&lt;p&gt;OpenStack is composed of many different projects for different purposes (compute, storage, networking, telemetry, etc.). Before you start contributing, you must have an idea of which project you actually want to contribute to. In my case I have decided on the &lt;a href=&#34;https://wiki.openstack.org/wiki/Telemetry&#34;&gt;Telemetry&lt;/a&gt; part, more specifically on &lt;strong&gt;Ceilometer&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;After you have picked a project, it is time to start reading its documentation and developer documentation to understand how it works. The &lt;a href=&#34;https://docs.openstack.org/developer/ceilometer/&#34;&gt;Ceilometer developer documentation&lt;/a&gt; offers good explanations and diagrams of its architecture and components.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://wiki.openstack.org/wiki/Ceilometer/Contributing&#34;&gt;Here&lt;/a&gt; is another nice guide on contributing to Ceilometer.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Python Tricks for Better Code</title>
      <link>https://aalvrz.me/posts/python-tricks-for-better-code/</link>
      <pubDate>Wed, 08 Mar 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/python-tricks-for-better-code/</guid>
      <description>&lt;p&gt;A compilation of very useful Python tricks for better code. All examples are Python 2.7 and Python 3 compatible unless stated otherwise.&lt;/p&gt;
&lt;h2 id=&#34;enumerate&#34;&gt;Enumerate&lt;/h2&gt;
&lt;p&gt;When working with items in a list and we want to print or handle each item&#39;s index, instead of using a counter variable:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# Bad way&lt;/span&gt;
&lt;span style=&#34;color:#111&#34;&gt;i&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;
&lt;span style=&#34;color:#00a8c8&#34;&gt;for&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;place&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;places&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;
    &lt;span style=&#34;color:#00a8c8&#34;&gt;print&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;i&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;place&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;
    &lt;span style=&#34;color:#111&#34;&gt;i&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;+&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We can use &lt;code&gt;enumerate&lt;/code&gt; to improve our code:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;color:#00a8c8&#34;&gt;for&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;i&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;place&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;enumerate&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;places&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;
    &lt;span style=&#34;color:#00a8c8&#34;&gt;print&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;i&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;place&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;enumerate&lt;/code&gt; returns a list of indexes along with each item in the list.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Integrating TravisCI With Rails and Heroku</title>
      <link>https://aalvrz.me/posts/integrating-travisci-with-rails-and-heroku/</link>
      <pubDate>Tue, 07 Mar 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/integrating-travisci-with-rails-and-heroku/</guid>
      <description>&lt;p&gt;Adding &lt;a href=&#34;https://travis-ci.org/&#34;&gt;TravisCI&lt;/a&gt; to your application&#39;s deployment flow will enable you to spot any build fails or test fails during deployment without affecting your production environment.&lt;/p&gt;
&lt;p&gt;In this post I go over on how to integrate TravisCI with a Rails 4 application that uses Postgresql, Rspec, and is later deployed to Heroku if the Travis build is successful.&lt;/p&gt;
&lt;h2 id=&#34;setting-up-travisci&#34;&gt;Setting up TravisCI&lt;/h2&gt;
&lt;p&gt;Assuming you already have an account in TravisCI, look for the Github repository of the Rails application and enable it. Then we will want to add a &lt;code&gt;.travis.yml&lt;/code&gt; file to the application&#39;s root directory with the following contents:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-yaml&#34; data-lang=&#34;yaml&#34;&gt;language&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt; Ruby
rvm&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;
  - &lt;span style=&#34;color:#ae81ff&#34;&gt;2.3&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;.0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The configuration above tells TravisCI that our application will use Ruby 2.3.0. Once you commit and push the change above to the master branch, Travis will begin creating the build, which might take a few minutes.&lt;/p&gt;
&lt;h3 id=&#34;configure-postgresql&#34;&gt;Configure Postgresql&lt;/h3&gt;
&lt;p&gt;Seems our Rails application uses Postgresql, we need to configure TravisCI to run our build with a Postgresql database. To do this we will add the following configuration to &lt;code&gt;.travis.yml&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-yaml&#34; data-lang=&#34;yaml&#34;&gt;services&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;
  - postgresql
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then we will add another configuration that will make Travis create a Postgresql database with username &lt;code&gt;postgres&lt;/code&gt; and blank password for the build:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-yaml&#34; data-lang=&#34;yaml&#34;&gt;before_script&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;
  - psql -c &lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;create database travis_ci_test;&amp;#39;&lt;/span&gt; -U postgres
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
    </item>
    
    <item>
      <title>Chinese Onomatopoeia in Literature</title>
      <link>https://aalvrz.me/posts/chinese-onomatopoeia-in-literature/</link>
      <pubDate>Mon, 06 Mar 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/chinese-onomatopoeia-in-literature/</guid>
      <description>&lt;p&gt;It&#39;s been almost a year since I started reading the Harry Potter series completely in Traditional Chinese, currently I just recently started &lt;em&gt;Harry Potter and the Order of the Phoenix&lt;/em&gt; (Book #5).&lt;/p&gt;
&lt;p&gt;Through my Chinese reading journey I have come accross a lot of Chinese &lt;a href=&#34;https://en.wikipedia.org/wiki/Onomatopoeia&#34;&gt;onomatopoeia&lt;/a&gt; that you don&#39;t really come across with in other types of writings such as Internet articles, conversations, and newspaper articles.&lt;/p&gt;
&lt;p&gt;In this post I go into detail about each of these sounds I encounter in literature.&lt;/p&gt;
&lt;h2 id=&#34;-gl&#34;&gt;咕嚕 (gūlū)&lt;/h2&gt;
&lt;p&gt;&lt;img src=&#34;http://1.bp.blogspot.com/-MpohU7WZ4TU/UCldacYdETI/AAAAAAAAACc/98W-mOiWIUM/s1600/hungry+stomach.jpg&#34; alt=&#34;Hungry&#34;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Definition:&lt;/strong&gt; rumble, roll.&lt;/p&gt;
&lt;p&gt;Used a lot when describing the rumbling sound of the stomach when hungry.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Examples:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;他的肚子&lt;strong&gt;咕嚕咕嚕&lt;/strong&gt;直響 - His stomach kept rumbling).&lt;/li&gt;
&lt;li&gt;粗大的圓木&lt;strong&gt;咕嚕咕嚕&lt;/strong&gt;地從山坡上滾下來 - Large logs came rolling down the slope&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;-pp&#34;&gt;啪啪 (pāpā)&lt;/h2&gt;
&lt;p&gt;&lt;img src=&#34;http://www.shapingyouth.org/wp-content/uploads/2015/05/hands-clapping-clip-art.png&#34; alt=&#34;Clapping&#34;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Definition:&lt;/strong&gt;  The sound of clapping, slapping, a gunshot.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Examples:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;啪&lt;/strong&gt;的一聲, 瓶塞飛出來了 - The cork popped and flew out of the bottle.&lt;/li&gt;
&lt;/ul&gt;</description>
    </item>
    
    <item>
      <title>Working With Zenoss Python Data Source Plugins</title>
      <link>https://aalvrz.me/posts/working-with-zenoss-python-data-sources/</link>
      <pubDate>Thu, 23 Feb 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/working-with-zenoss-python-data-sources/</guid>
      <description>&lt;p&gt;Using Python data source plugins in Zenoss is a great way to collect data, and probably a better way than using &lt;a href=&#34;https://aalvrz.me/posts/ssh-monitoring-in-zenpacks.html&#34;&gt;command datasources&lt;/a&gt;. Python data sources come with the introduction of the &lt;a href=&#34;https://www.zenoss.com/product/zenpacks/pythoncollector&#34;&gt;PythonCollector ZenPack&lt;/a&gt;, so this ZenPack is required in order to start using Python data sources in our own ZenPacks.&lt;/p&gt;
&lt;p&gt;Python data source plugins work exceptionally great in replacing data collection logic in &lt;a href=&#34;https://aalvrz.me/posts/creating-zenoss-zenpack-daemons.html&#34;&gt;custom daemons&lt;/a&gt; written in Python. This means that the ZenPacks&#39;s code is greatly reduced because we do not have to create configuration service, and custom daemon code.&lt;/p&gt;
&lt;p&gt;Moreover, while Python data source plugins are Python-based, we can still execute shell commands within the plugin.&lt;/p&gt;
&lt;h2 id=&#34;example-scenario-bmc-power-status&#34;&gt;Example Scenario: BMC Power Status&lt;/h2&gt;
&lt;p&gt;For this post, I will be using an example where we will be executing an &lt;a href=&#34;https://aalvrz.me/posts/ipmi-baseboard-management-controllers.html&#34;&gt;ipmitool command&lt;/a&gt; to check the power chassis status of a &lt;a href=&#34;https://aalvrz.me/posts/ipmi-baseboard-management-controllers.html&#34;&gt;BMC device&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If I run the following command from my shell:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;ipmitool -H $BMC_IP -I lanplus -U admin -P admin power status
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I get the following output:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Chassis Power is on
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;What we want is our data source plugin to periodically and continuously execute this command and obtain the value. Our ZenPack will then proceed to:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Map the value into a boolean property of a custon zenpacklib class.&lt;/li&gt;
&lt;li&gt;Create a CRITICAL event if the power status is off or if the command fails. Create a CLEAR event if the power status is on.&lt;/li&gt;
&lt;li&gt;Update the device model with the new property value.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://aalvrz.me/posts/modifying-the-zenoss-device-detail-bar.html&#34;&gt;Display the property&#39;s value in the device detail bar using JavaScript&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;</description>
    </item>
    
    <item>
      <title>Useful Zendmd Tricks</title>
      <link>https://aalvrz.me/posts/useful-zendmd-tricks/</link>
      <pubDate>Tue, 14 Feb 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/useful-zendmd-tricks/</guid>
      <description>&lt;p&gt;The &lt;a href=&#34;http://wiki.zenoss.org/Category:ZenDMD&#34;&gt;Zenoss Zendmd Tips Wiki&lt;/a&gt; page contains a few useful tricks using zendmd to perform tasks. In this post I am adding more tricks that I discover and learn along the way.&lt;/p&gt;
&lt;h2 id=&#34;removing-device-classes&#34;&gt;Removing Device Classes&lt;/h2&gt;
&lt;p&gt;We can easily remove device classes within zendmd with a simple command. Assuming we want to remove the default &amp;ldquo;KVM&amp;rdquo; device class:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;color:#111&#34;&gt;dmd&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;Devices&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;manage_deleteOrganizer&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;/zport/dmd/Devices/KVM&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;
&lt;span style=&#34;color:#111&#34;&gt;commit&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;change-zenoss-users-password&#34;&gt;Change Zenoss User&#39;s Password&lt;/h2&gt;
&lt;p&gt;Let&#39;s say we want to change the default &lt;em&gt;admin&lt;/em&gt; user&#39;s password (&lt;code&gt;zenoss&lt;/code&gt;) in the Ubuntu auto deploy:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;color:#111&#34;&gt;app&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;acl_users&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;userManager&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;updateUserPassword&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;admin&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;newpassword&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;
&lt;span style=&#34;color:#111&#34;&gt;commit&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
    </item>
    
    <item>
      <title>Getting Started With Juju Locally</title>
      <link>https://aalvrz.me/posts/getting-started-with-juju-locally/</link>
      <pubDate>Fri, 10 Feb 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/getting-started-with-juju-locally/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://jujucharms.com/&#34;&gt;Juju&lt;/a&gt; is a great tool that allows us to deploy many services in a local or cloud environment. Services are deployed into virtual containers and can be removed and re-deployed at any time. It is perfect for creating sandbox and test environments for specific kind of services that you develop for.&lt;/p&gt;
&lt;p&gt;In this post I will explain how easy it is to get started with Juju in a &lt;strong&gt;local&lt;/strong&gt; environment.&lt;/p&gt;
&lt;h2 id=&#34;installation&#34;&gt;Installation&lt;/h2&gt;
&lt;p&gt;To start we will need to add the necessary repository from where we will retrieve the Juju packages:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;sudo add-apt-repository ppa:juju/stable
sudo apt-get update
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Next we will download and install the Juju core package &lt;strong&gt;and&lt;/strong&gt; the package for local deployment:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;sudo apt-get install juju-core
sudo apt-get install juju-local
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;setting-up-the-local-environment&#34;&gt;Setting Up the Local Environment&lt;/h2&gt;
&lt;p&gt;Before we set up the local environment, let&#39;s first generate a configuration file. This file will contain the configuration for many kinds of environments (OpenStack, AWS, MaaS, etc.), including a local environment configuration. We will generate the file and then switch to the local environment:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;juju generate-config
juju switch local
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Once we have switched to the local environment, we can simply bootstrap the environment with the following command:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;juju bootstrap
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;After the process is complete, we are now ready to start using Juju.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>C Gotchas For Beginners</title>
      <link>https://aalvrz.me/posts/c-gotchas-for-beginners/</link>
      <pubDate>Tue, 07 Feb 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/c-gotchas-for-beginners/</guid>
      <description>&lt;p&gt;Similar to &lt;a href=&#34;https://aalvrz.me/posts/javascript-gotchas-for-beginners.html&#34;&gt;my post&lt;/a&gt; on some must-know concepts about JavaScript for beginners, this is a list of concepts that show how C differs from other programming languages. These are concepts that you &lt;strong&gt;must&lt;/strong&gt; know if you are to become a good C programmer.&lt;/p&gt;
&lt;h2 id=&#34;boolean-types&#34;&gt;Boolean Types&lt;/h2&gt;
&lt;p&gt;C actually does not have a boolean type. They are usually defined like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-c&#34; data-lang=&#34;c&#34;&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#&lt;/span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;define BOOL char&lt;/span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;
&lt;/span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#&lt;/span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;define FALSE 0&lt;/span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;
&lt;/span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#&lt;/span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;define TRUE 1&lt;/span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;However it is argued that it is a better practice to simply use integers instead (&lt;code&gt;0&lt;/code&gt; and &lt;code&gt;1&lt;/code&gt;).&lt;/p&gt;
&lt;h2 id=&#34;memory-address-of-array-elements&#34;&gt;Memory Address of Array Elements&lt;/h2&gt;
&lt;p&gt;In C, arrays have a contiguous memory allocation. We can verify this by printing the memory addresses of each element of an array. We can do so using &lt;code&gt;&amp;amp;&lt;/code&gt; to access the memory location of the array element:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-c&#34; data-lang=&#34;c&#34;&gt;&lt;span style=&#34;color:#00a8c8&#34;&gt;int&lt;/span&gt; &lt;span style=&#34;color:#75af00&#34;&gt;main&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;{&lt;/span&gt;
  &lt;span style=&#34;color:#00a8c8&#34;&gt;char&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;vowels&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;[&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;]&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;{&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;a&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;e&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;i&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;o&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;u&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;;&lt;/span&gt;

  &lt;span style=&#34;color:#00a8c8&#34;&gt;for&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#00a8c8&#34;&gt;int&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;i&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;;&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;i&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;5&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;;&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;i&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;+&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;+&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;{&lt;/span&gt;
    &lt;span style=&#34;color:#111&#34;&gt;printf&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;Address of vowel [%d]: %u&lt;/span&gt;&lt;span style=&#34;color:#8045ff&#34;&gt;\n&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;i&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;vowels&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;[&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;i&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;]&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;;&lt;/span&gt;
  &lt;span style=&#34;color:#111&#34;&gt;}&lt;/span&gt;

  &lt;span style=&#34;color:#00a8c8&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;;&lt;/span&gt;
&lt;span style=&#34;color:#111&#34;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The above code will produces the following output for me:&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Processing Nova Live Migration Events in Zenoss</title>
      <link>https://aalvrz.me/posts/processing-nova-live-migration-events-in-zenoss/</link>
      <pubDate>Mon, 23 Jan 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/processing-nova-live-migration-events-in-zenoss/</guid>
      <description>&lt;p&gt;When monitoring OpenStack using the OpenStack Infrastructure ZenPack integrated with Ceilometer, it is possible to get fast virtual machine state changes (on/off powering, etc.) by receiving events sent from Ceilometer to Zenoss.&lt;/p&gt;
&lt;p&gt;However I discovered that when trying to get the same effect for &lt;strong&gt;live migration&lt;/strong&gt; (live migrating a virtual machine from one compute node to another) scenarios, this would not work. I proceeded to investigate why.&lt;/p&gt;
&lt;h2 id=&#34;ceilometer-dispatcher-live-migration-events&#34;&gt;Ceilometer Dispatcher Live Migration Events&lt;/h2&gt;
&lt;p&gt;I decided that the first thing to check was if the &lt;a href=&#34;https://github.com/zenoss/ceilometer_zenoss&#34;&gt;Zenoss Ceilometer dispatcher&lt;/a&gt; was &lt;strong&gt;capturing&lt;/strong&gt; and &lt;strong&gt;sending&lt;/strong&gt; the live migration events to Zenoss. Indeed, the logs can be found in Ceilometer under &lt;code&gt;/var/log/ceilometer/ceilometer-collector.log&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;2017-01-23 14:22:02.593 25667 INFO ceilometer_zenoss.dispatcher.zenoss [-] record_events called (events=[&amp;lt;Event: 3538a01c-ab8d-4e64-b0ff-6e8fe270e06a, compute.instance.live_migration.post.dest.start, 2017-01-23 06:22:02.584049, &amp;lt;Trait: state_description 1 migrating&amp;gt; &amp;lt;Trait: memory_mb 2 512&amp;gt; &amp;lt;Trait: ephemeral_gb 2 0&amp;gt; &amp;lt;Trait: fixed_ips 1 [{u&#39;version&#39;: 4, u&#39;vif_mac&#39;: u&#39;fa:16:3e:6e:02:e9&#39;, u&#39;floating_ips&#39;: [], u&#39;label&#39;: u&#39;admin-net&#39;, u&#39;meta&#39;: {}, u&#39;address&#39;: u&#39;192.168.0.15&#39;, u&#39;type&#39;: u&#39;fixed&#39;}]&amp;gt; &amp;lt;Trait: user_id 1 6d581c230c86475abf70cce41440e8a1&amp;gt; &amp;lt;Trait: service 1 compute&amp;gt; &amp;lt;Trait: priority 1 info&amp;gt; &amp;lt;Trait: state 1 active&amp;gt; &amp;lt;Trait: launched_at 4 2017-01-23 05:06:41&amp;gt; &amp;lt;Trait: flavor_name 1 m1.tiny&amp;gt; &amp;lt;Trait: disk_gb 2 1&amp;gt; &amp;lt;Trait: display_name 1 pdcmtest&amp;gt; &amp;lt;Trait: root_gb 2 1&amp;gt; &amp;lt;Trait: tenant_id 1 10296907e44248d2a707689f77d59ef6&amp;gt; &amp;lt;Trait: instance_id 1 87be4b45-e214-4ca3-8f5c-1bd31159f9e4&amp;gt; &amp;lt;Trait: vcpus 2 1&amp;gt; &amp;lt;Trait: host_name 1 ndc27-3222&amp;gt; &amp;lt;Trait: request_id 1 req-d4c27d06-6329-4ce0-adb5-370b8ca83a22&amp;gt;&amp;gt;])

2017-01-23 14:22:02.771 25667 INFO ceilometer_zenoss.dispatcher.zenoss [-] record_events called (events=[&amp;lt;Event: 8db64329-606c-4184-9b5b-eb815166cb17, compute.instance.live_migration.post.dest.end, 2017-01-23 06:22:02.761138, &amp;lt;Trait: state_description 1 &amp;gt; &amp;lt;Trait: memory_mb 2 512&amp;gt; &amp;lt;Trait: ephemeral_gb 2 0&amp;gt; &amp;lt;Trait: fixed_ips 1 [{u&#39;version&#39;: 4, u&#39;vif_mac&#39;: u&#39;fa:16:3e:6e:02:e9&#39;, u&#39;floating_ips&#39;: [], u&#39;label&#39;: u&#39;admin-net&#39;, u&#39;meta&#39;: {}, u&#39;address&#39;: u&#39;192.168.0.15&#39;, u&#39;type&#39;: u&#39;fixed&#39;}]&amp;gt; &amp;lt;Trait: user_id 1 6d581c230c86475abf70cce41440e8a1&amp;gt; &amp;lt;Trait: service 1 compute&amp;gt; &amp;lt;Trait: priority 1 info&amp;gt; &amp;lt;Trait: state 1 active&amp;gt; &amp;lt;Trait: launched_at 4 2017-01-23 05:06:41&amp;gt; &amp;lt;Trait: flavor_name 1 m1.tiny&amp;gt; &amp;lt;Trait: disk_gb 2 1&amp;gt; &amp;lt;Trait: display_name 1 pdcmtest&amp;gt; &amp;lt;Trait: root_gb 2 1&amp;gt; &amp;lt;Trait: tenant_id 1 10296907e44248d2a707689f77d59ef6&amp;gt; &amp;lt;Trait: instance_id 1 87be4b45-e214-4ca3-8f5c-1bd31159f9e4&amp;gt; &amp;lt;Trait: vcpus 2 1&amp;gt; &amp;lt;Trait: host_name 1 ndc27-3222&amp;gt; &amp;lt;Trait: request_id 1 req-d4c27d06-6329-4ce0-adb5-370b8ca83a22&amp;gt;&amp;gt;])

2017-01-23 14:22:02.782 25667 INFO ceilometer_zenoss.dispatcher.zenoss [-] record_events called (events=[&amp;lt;Event: d0dc4f4a-454a-42c5-b767-386dc3e0d1f3, compute.instance.live_migration._post.end, 2017-01-23 06:22:02.776665, &amp;lt;Trait: state_description 1 migrating&amp;gt; &amp;lt;Trait: memory_mb 2 512&amp;gt; &amp;lt;Trait: ephemeral_gb 2 0&amp;gt; &amp;lt;Trait: fixed_ips 1 [{u&#39;version&#39;: 4, u&#39;vif_mac&#39;: u&#39;fa:16:3e:6e:02:e9&#39;, u&#39;floating_ips&#39;: [], u&#39;label&#39;: u&#39;admin-net&#39;, u&#39;meta&#39;: {}, u&#39;address&#39;: u&#39;192.168.0.15&#39;, u&#39;type&#39;: u&#39;fixed&#39;}]&amp;gt; &amp;lt;Trait: user_id 1 6d581c230c86475abf70cce41440e8a1&amp;gt; &amp;lt;Trait: service 1 compute&amp;gt; &amp;lt;Trait: priority 1 info&amp;gt; &amp;lt;Trait: state 1 active&amp;gt; &amp;lt;Trait: launched_at 4 2017-01-23 05:06:41&amp;gt; &amp;lt;Trait: flavor_name 1 m1.tiny&amp;gt; &amp;lt;Trait: disk_gb 2 1&amp;gt; &amp;lt;Trait: display_name 1 pdcmtest&amp;gt; &amp;lt;Trait: root_gb 2 1&amp;gt; &amp;lt;Trait: tenant_id 1 10296907e44248d2a707689f77d59ef6&amp;gt; &amp;lt;Trait: instance_id 1 87be4b45-e214-4ca3-8f5c-1bd31159f9e4&amp;gt; &amp;lt;Trait: vcpus 2 1&amp;gt; &amp;lt;Trait: host_name 1 ndc27-3205&amp;gt; &amp;lt;Trait: request_id 1 req-d4c27d06-6329-4ce0-adb5-370b8ca83a22&amp;gt;&amp;gt;])
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Notice the &lt;code&gt;live_migration.post.dest.start&lt;/code&gt; and &lt;code&gt;live_migration.post.dest.end&lt;/code&gt; logs.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Appending Modeler Plugins in ZenPacks</title>
      <link>https://aalvrz.me/posts/appending-modeler-plugins-in-zenpacks/</link>
      <pubDate>Fri, 20 Jan 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/appending-modeler-plugins-in-zenpacks/</guid>
      <description>&lt;p&gt;When creating ZenPacks using zenpacklib, assigning modeler plugins to device classes will cause all the device class&#39;s modeler plugins to be &lt;strong&gt;replaced&lt;/strong&gt; by the new modeler plugins assigned by the ZenPack. Obviously most of the time this is not the behaviour we want. What we really want is that the new modeler plugins are simply &lt;em&gt;added&lt;/em&gt; to the device class&#39;s list of modeler plugins.&lt;/p&gt;
&lt;p&gt;In a previous post I explained how we can &lt;a href=&#34;https://aalvrz.me/posts/customizing-the-zenpack-installation-process.html&#34;&gt;customize the ZenPacks installation process&lt;/a&gt; to perform additional tasks. The way to append new modeler plugins to a device class follows this concept.&lt;/p&gt;
&lt;p&gt;Let&#39;s assume that we have the &lt;a href=&#34;http://wiki.zenoss.org/ZenPack:OpenStack_(Provider_View)&#34;&gt;OpenStack Infrastructure ZenPack&lt;/a&gt; installed in our Zenoss Core. This ZenPack adds some custom modeler plugins to the &lt;code&gt;/Server/SSH/Linux/NovaHost&lt;/code&gt; device class. We want our custom ZenPack to add &lt;em&gt;new&lt;/em&gt; modeler plugins to this device class without replacing the ones added by the OpenStack ZenPack.&lt;/p&gt;
&lt;p&gt;This will be done upon installation (like in the previous post) inside the &lt;code&gt;__init__.py&lt;/code&gt; file in the ZenPack top directory. This is how the code looks like:&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Customizing the ZenPack Installation Process</title>
      <link>https://aalvrz.me/posts/customizing-the-zenpack-installation-process/</link>
      <pubDate>Tue, 17 Jan 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/customizing-the-zenpack-installation-process/</guid>
      <description>&lt;p&gt;There are some circumstances where we need to perform certain tasks in our ZenPack the moment it is installed. We can achieve this using Python by placing this logic inside the ZenPack&#39;s top directory&#39;s &lt;code&gt;__init__.py&lt;/code&gt; file. When creating a fresh ZenPack using &lt;strong&gt;zenpacklib&lt;/strong&gt;, this &lt;code&gt;__init__.py&lt;/code&gt; file will contain the following contents:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;zenpacklib&lt;/span&gt;

&lt;span style=&#34;color:#111&#34;&gt;CFG&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;zenpacklib&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;load_yaml&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;To add custom functionality that gets executed when the ZenPack is installed, we need to extend the &lt;code&gt;install&lt;/code&gt; method of the &lt;code&gt;ZenPack&lt;/code&gt; class. Below the original code, we can proceed to do so:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;color:#00a8c8&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#75af00&#34;&gt;ZenPack&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;schema&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;ZenPack&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;
    &lt;span style=&#34;color:#00a8c8&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#75af00&#34;&gt;install&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;self&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;app&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;
        &lt;span style=&#34;color:#75715e&#34;&gt;# Our custom logic here&lt;/span&gt;

        &lt;span style=&#34;color:#111&#34;&gt;super&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;ZenPack&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;self&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;install&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;app&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;No other imports are necessary. Notice the last line of the &lt;code&gt;install&lt;/code&gt; method, this is where the ZenPack gets installed.&lt;/p&gt;
&lt;p&gt;For the purpuse of giving an example, Let&#39;s say that our ZenPack creates two new &lt;a href=&#34;https://zenpack-sdk.zenoss.com/en/latest/yaml-zProperties.html&#34;&gt;zProperties&lt;/a&gt;, one property to store an API key, and the other one to store a URL. Moreover let&#39;s say that we obtain these values from somewhere and we want to assign them &lt;strong&gt;automatically&lt;/strong&gt; to the properties upon the installation of the ZenPack.&lt;/p&gt;
&lt;p&gt;These two new properties are defined in &lt;code&gt;zenpack.yaml&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-yaml&#34; data-lang=&#34;yaml&#34;&gt;name&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt; ZenPacks.aalvarez.MyZenPack

zProperties&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;
  zMyApiUrl&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;
    category&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt; MyApi
    type&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt; string

  zMyApiKey&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;
    category&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt; MyApi
    type&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt; string
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
    </item>
    
    <item>
      <title>Understanding SNMP and Net-SNMP</title>
      <link>https://aalvrz.me/posts/understanding-snmp-and-net-snmp/</link>
      <pubDate>Mon, 16 Jan 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/understanding-snmp-and-net-snmp/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;http://net-snmp.sourceforge.net/&#34;&gt;Net-SNMP&lt;/a&gt; is a suite of tools used to implement SNMP (Simple Network Management Protocol). SNMP is a widely used protocol for monitoring the health and welfare of network equipment (eg. routers), computer equipment and even devices like UPSs. Net-SNMP includes tools with capabilities such as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;An extensible agent&lt;/li&gt;
&lt;li&gt;An SNMP library&lt;/li&gt;
&lt;li&gt;Tools to request or set information from SNMP agents&lt;/li&gt;
&lt;li&gt;Tools to generate and handle SNMP traps&lt;/li&gt;
&lt;li&gt;A version of the unix &amp;lsquo;netstat&amp;rsquo; command using SNMP&lt;/li&gt;
&lt;li&gt;A graphical Perl/Tk/SNMP based mib browser&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;how-snmp-works&#34;&gt;How SNMP Works&lt;/h2&gt;
&lt;p&gt;SNMP allows a management station to treat its network as a distributed database of health and configuration information. SNMP contains a small set of operations:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;GET: Retrieve data from a network node&lt;/li&gt;
&lt;li&gt;GETNEXT: Retrieve the next element from a network node&lt;/li&gt;
&lt;li&gt;SET: Send configuration or control commands to a network node&lt;/li&gt;
&lt;li&gt;TRAP: A network node can send a notification to the management station&lt;/li&gt;
&lt;li&gt;INFORM: An acknowledged trap (network nodes can try and send it again if no acknowledgement is received)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&#34;http://computernetworkingsimplified.com/wp-content/uploads/2014/02/snmparchitecture1.jpg&#34; alt=&#34;SNMP Architecture&#34;&gt;&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Fixing Zenoss Device Network Interface Graphs</title>
      <link>https://aalvrz.me/posts/fixing-zenoss-device-network-interface-graphs/</link>
      <pubDate>Fri, 13 Jan 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/fixing-zenoss-device-network-interface-graphs/</guid>
      <description>&lt;p&gt;When testing the monitoring of the OpenStack compute node devices in Zenoss (using &lt;a href=&#34;http://wiki.zenoss.org/ZenPack:OpenStack_(Provider_View)&#34;&gt;OpenStack Infrastructure ZenPack&lt;/a&gt;), I noticed that I could not get any graphs for the &lt;strong&gt;network interfaces&lt;/strong&gt; of the device, although we could still get and model all the available interfaces:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://aalvrz.me/posts/fixing-zenoss-device-network-interface-graphs/network_interfaces.png&#34; alt=&#34;Network Interfaces&#34;&gt;&lt;/p&gt;
&lt;p&gt;This was indeed strange because I could perfectly get the graphs for other devices. After a lot of head scratching and prying around the code and interface, I finally found the reason, which I explain below.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>JavaScript Gotchas for Beginners</title>
      <link>https://aalvrz.me/posts/javascript-gotchas-for-beginners/</link>
      <pubDate>Fri, 06 Jan 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/javascript-gotchas-for-beginners/</guid>
      <description>&lt;p&gt;When starting to learn JavaScript, there are a few details and gotchas that are always important to remember. Memorizing and understanding these concepts will make you a better and faster JavaScript programmer overall and it is why I am listing a few of these concepts (which are best learned at the beginner level) in this post.&lt;/p&gt;
&lt;h2 id=&#34;the-global-object&#34;&gt;The Global Object&lt;/h2&gt;
&lt;p&gt;The &lt;strong&gt;global scope&lt;/strong&gt; is the space in which global variables live and it can also be approached as an object. Each global variable is present as a &lt;strong&gt;property&lt;/strong&gt; of this object. In browsers, the global scope object is stored in the &lt;code&gt;window&lt;/code&gt; variable:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;color:#00a8c8&#34;&gt;var&lt;/span&gt; &lt;span style=&#34;color:#75af00&#34;&gt;v&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;10&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;;&lt;/span&gt;
&lt;span style=&#34;color:#75af00&#34;&gt;console&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#75af00&#34;&gt;log&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#34;v&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#00a8c8&#34;&gt;in&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;window&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;;&lt;/span&gt;
&lt;span style=&#34;color:#75715e&#34;&gt;// &amp;gt; true
&lt;/span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#75af00&#34;&gt;console&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#75af00&#34;&gt;log&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;window&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#75af00&#34;&gt;v&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;;&lt;/span&gt;
&lt;span style=&#34;color:#75715e&#34;&gt;// &amp;gt; 10
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
    </item>
    
    <item>
      <title>Custom Pages in Zenoss</title>
      <link>https://aalvrz.me/posts/custom-pages-in-zenoss/</link>
      <pubDate>Mon, 26 Dec 2016 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/custom-pages-in-zenoss/</guid>
      <description>&lt;p&gt;In a &lt;a href=&#34;https://aalvrz.me/posts/extending-zenoss-navigations.html&#34;&gt;previous post&lt;/a&gt; I talked about how to create custom navigation links in Zenoss using a ZenPack. However we didn&#39;t get to creating the custom pages that these links would link to. This is what we will learn today.&lt;/p&gt;
&lt;h2 id=&#34;page-viewlets&#34;&gt;Page Viewlets&lt;/h2&gt;
&lt;p&gt;Previously we created navigation item viewlets, this time we will be creating &lt;strong&gt;page&lt;/strong&gt; viewlets. These type of viewlets allow us to create and insert new custom pages into Zenoss where we can display custom content. To create a new page, we add the following code to &lt;code&gt;browser/configure.zcml&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-xml&#34; data-lang=&#34;xml&#34;&gt;&lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;browser:page&lt;/span&gt;
  &lt;span style=&#34;color:#75af00&#34;&gt;name=&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#34;secondaryPage&amp;#34;&lt;/span&gt;
  &lt;span style=&#34;color:#75af00&#34;&gt;for=&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#34;*&amp;#34;&lt;/span&gt;
  &lt;span style=&#34;color:#75af00&#34;&gt;permission=&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#34;zenoss.View&amp;#34;&lt;/span&gt;
  &lt;span style=&#34;color:#75af00&#34;&gt;template=&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#34;templates/my_template.pt&amp;#34;&lt;/span&gt;
  &lt;span style=&#34;color:#f92672&#34;&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;It is important that the &lt;strong&gt;name&lt;/strong&gt; attribute matches the URL of the navigation link we created previously. Another important attribute is the &lt;strong&gt;template&lt;/strong&gt; attribute, this is a special file that will represent the base markup of the page using a combination of HTML, TAL, and &lt;a href=&#34;http://old.zope.org/Members/tone/METAL&#34;&gt;METAL&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Also let&#39;s not forget to create a necessary python init file:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;touch browser/__init__.py
&lt;/code&gt;&lt;/pre&gt;</description>
    </item>
    
    <item>
      <title>Cracking Passwords With aircrack-ng</title>
      <link>https://aalvrz.me/posts/cracking-passwords-with-aircrack-ng/</link>
      <pubDate>Sun, 25 Dec 2016 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/cracking-passwords-with-aircrack-ng/</guid>
      <description>&lt;p&gt;aircrack-ng is a powerful suite of tools that allows to assess wireless network security. The tools in the suite allows us to perform various actions such as packet monitoring in the environment, montoring of specific access points, de-authentication attacks on access points, and cracking of WEP and WPA PSK (WPA 1 and 2) passwords.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;http://www.aircrack-ng.org/resources/aircrack-ng-new-logo.jpg&#34; alt=&#34;aircrack-ng&#34;&gt;&lt;/p&gt;
&lt;p&gt;In this post I will explain on how to perform these actions.&lt;/p&gt;
&lt;h2 id=&#34;wireless-card-monitor-mode&#34;&gt;Wireless Card Monitor Mode&lt;/h2&gt;
&lt;p&gt;Before we begin it is crucial that we change the mode of our wireless network card to &lt;strong&gt;monitor mode&lt;/strong&gt;. BY default, our wireless network card&#39;s mode is &lt;strong&gt;managed mode&lt;/strong&gt;. In managed mode, the network card generally only listens to packets addressed to the card, whereas in monitor mode it will hear &lt;strong&gt;every packet in the air&lt;/strong&gt;. Additionally, monitor mode will also allows us to perform packet injection attacks (i.e. de-authentication attacks).&lt;/p&gt;
&lt;p&gt;To set our network card into monitor mode, we can run the following commands in a terminal:&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Extending Zenoss Navigation Bars</title>
      <link>https://aalvrz.me/posts/extending-zenoss-navigations/</link>
      <pubDate>Wed, 21 Dec 2016 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/extending-zenoss-navigations/</guid>
      <description>&lt;p&gt;It is possible to extend the functionality of Zenoss&#39;s navigations from within our custom ZenPacks. This means that we can add or remove links to the navigation bars we frequently use to access the infrastructure page or event console.&lt;/p&gt;
&lt;h2 id=&#34;configurezcml&#34;&gt;configure.zcml&lt;/h2&gt;
&lt;p&gt;Zenoss ZenPacks can contain a file in the ZenPack top directory called &lt;code&gt;configure.zcml&lt;/code&gt;. I&#39;ve mentioned and talked about this particular file in previous posts. This file basically acts as a configuration glue between back-end functions and front-end components.&lt;/p&gt;
&lt;p&gt;It is in this file where we will declare and create new navigational links from our ZenPack.&lt;/p&gt;
&lt;p&gt;~&amp;gt; In this post we assume that the ZenPack is created using &lt;a href=&#34;https://zenpacklib.zenoss.com/en/latest/&#34;&gt;zenpacklib&lt;/a&gt;, which is a Python library that makes creating ZenPacks much easier. Zenpacklib also makes the integration between the back-end and front-end much easier as well.&lt;/p&gt;
&lt;p&gt;Usually this file begins with some required boilerplate code:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;configure.zcml&lt;/strong&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-xml&#34; data-lang=&#34;xml&#34;&gt;&lt;span style=&#34;color:#75715e&#34;&gt;&amp;lt;?xml version=&amp;#34;1.0&amp;#34; encoding=&amp;#34;utf-8&amp;#34;?&amp;gt;&lt;/span&gt;
&lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;configure&lt;/span&gt;
  &lt;span style=&#34;color:#75af00&#34;&gt;xmlns=&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#34;http://namespaces.zope.org/zope&amp;#34;&lt;/span&gt;
  &lt;span style=&#34;color:#75af00&#34;&gt;xmlns:browser=&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#34;http://namespaces.zope.org/browser&amp;#34;&lt;/span&gt;
  &lt;span style=&#34;color:#75af00&#34;&gt;xmlns:zcml=&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#34;http://namespaces.zope.org/zcml&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;&amp;gt;&lt;/span&gt;

  &lt;span style=&#34;color:#75715e&#34;&gt;&amp;lt;!--&lt;/span&gt;&lt;span style=&#34;color:#75715e&#34;&gt; Our custom code here &lt;/span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;--&amp;gt;&lt;/span&gt;
  &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;include&lt;/span&gt; &lt;span style=&#34;color:#75af00&#34;&gt;package=&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#34;.browser&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;/&amp;gt;&lt;/span&gt;
&lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;/configure&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
    </item>
    
    <item>
      <title>Custom Zenoss API Endpoints</title>
      <link>https://aalvrz.me/posts/custom-zenoss-api-endpoints/</link>
      <pubDate>Tue, 20 Dec 2016 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/custom-zenoss-api-endpoints/</guid>
      <description>&lt;p&gt;In a &lt;a href=&#34;https://aalvrz.me/posts/the-zenoss-json-api.html&#34;&gt;previous post&lt;/a&gt; I went over the Zenoss JSON API and how it works inside the Zenoss Core. In this post we will apply the concepts learned in that post in order to create custom API endpoints within Zenoss, which can be accessed by the JavaScript front-end, &lt;em&gt;curl&lt;/em&gt;, API clients, etc. All this new functionality added from a basic ZenPack.&lt;/p&gt;
&lt;h2 id=&#34;creating-an-endpoint&#34;&gt;Creating an Endpoint&lt;/h2&gt;
&lt;p&gt;Assuming that we are starting with a new and fresh ZenPack created with &lt;a href=&#34;https://zenpacklib.zenoss.com/en/latest/&#34;&gt;zenpacklib&lt;/a&gt;, we will proceed to create a simple endpoint.&lt;/p&gt;
&lt;p&gt;Let&#39;s go ahead and create a file named &lt;code&gt;api.py&lt;/code&gt; (can be any name) under the ZenPack&#39;s top directory. In this file we will import necessary modules, implement interfaces, and define our &lt;strong&gt;routers&lt;/strong&gt; and &lt;strong&gt;facades&lt;/strong&gt;. If you still don&#39;t know what routers and facades are and what they do, I suggest you first take a look at &lt;a href=&#34;https://aalvrz.me/posts/the-zenoss-json-api.html&#34;&gt;The Zenoss JSON API&lt;/a&gt; post.&lt;/p&gt;
&lt;p&gt;First, let&#39;s take a quick look at the imports:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;os.path&lt;/span&gt;
&lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;urlparse&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;urlparse&lt;/span&gt;
&lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;subprocess&lt;/span&gt;

&lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;zope.event&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;notify&lt;/span&gt;
&lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;zope.interface&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;implements&lt;/span&gt;
&lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;ZODB.transact&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;transact&lt;/span&gt;

&lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;Products.ZenUtils.Ext&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;DirectRouter&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;DirectResponse&lt;/span&gt;
&lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;Products&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;Zuul&lt;/span&gt;
&lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;Products.Zuul.catalog.events&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;IndexingEvent&lt;/span&gt;
&lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;Products.Zuul.facades&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;ZuulFacade&lt;/span&gt;
&lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;Products.Zuul.interfaces&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;IFacade&lt;/span&gt;
&lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;Products.Zuul.utils&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;ZuulMessageFactory&lt;/span&gt; &lt;span style=&#34;color:#00a8c8&#34;&gt;as&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;_t&lt;/span&gt;
&lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;Products.ZenUtils.Utils&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;zenPath&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Some imports are probably not needed, but the ones that are of our interest are imports such as &lt;code&gt;DirectRouter&lt;/code&gt; and &lt;code&gt;DirectResponse&lt;/code&gt;, which you might remember from the previous post. Additionally we are also importing the necessary facade, events, and interfaces imports.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>SSH Monitoring in ZenPacks</title>
      <link>https://aalvrz.me/posts/ssh-monitoring-in-zenpacks/</link>
      <pubDate>Wed, 14 Dec 2016 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/ssh-monitoring-in-zenpacks/</guid>
      <description>&lt;p&gt;Zenoss usually monitors and collects information using &lt;strong&gt;SNMP&lt;/strong&gt; and &lt;strong&gt;SSH&lt;/strong&gt; methods. A good example of is the &lt;a href=&#34;http://wiki.zenoss.org/ZenPack:Linux_Monitor&#34;&gt;linux monitor ZenPack&lt;/a&gt; which can collect information such as hard disks, interfaces, and file systems using &lt;strong&gt;both&lt;/strong&gt; methods.&lt;/p&gt;
&lt;p&gt;SNMP works by installing and configuring an SNMP agent on the machine we want to monitor. This agent will poll the machine for data, and this data can be retrieved by Zenoss using &lt;strong&gt;&lt;a href=&#34;http://www.net-snmp.org/&#34;&gt;net-snmp&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;On the other hand, SSH works by configuring a username and password or a path to an SSH key zProperties. This will allow Zenoss to remotely access the host using SSH and execute the corresponding commands and return the corresponding information.&lt;/p&gt;
&lt;p&gt;When developing ZenPacks, data collection using SNMP is a relatively common practice. There is even a very good tutorial on &lt;a href=&#34;https://zenpacklib.zenoss.com/en/latest/tutorial-snmp-device/index.html&#34;&gt;SNMP monitoring using zenpacklib&lt;/a&gt;. When using SNMP, the modeler plugins are &lt;code&gt;SnmpPlugin&lt;/code&gt; plugins that typically work using a set of &lt;a href=&#34;http://www.dpstele.com/snmp/what-does-oid-network-elements.php&#34;&gt;OIDs&lt;/a&gt; to determine exactly which data is to be modeled.&lt;/p&gt;
&lt;h2 id=&#34;ssh-in-modeler-plugins&#34;&gt;SSH in Modeler Plugins&lt;/h2&gt;
&lt;p&gt;In order to make a modeler plugin utilize SSH as it&#39;s polling method we need to use a different type of plugin, the &lt;code&gt;CommandPlugin&lt;/code&gt; plugin. The structure of this type of plugin is very similar to the &lt;code&gt;SnmpPlugin&lt;/code&gt;, however there is one critical variable that must be implemented.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>IP Addresses - A Review</title>
      <link>https://aalvrz.me/posts/ip-addresses-a-review/</link>
      <pubDate>Fri, 02 Dec 2016 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/ip-addresses-a-review/</guid>
      <description>&lt;p&gt;&lt;em&gt;A review of IP addresses, as part of my Computer Networking Fundamentals series.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;A lot of people know what IP addresses are, and a lot of people also probably know that each device that is connected to the Internet must have a &lt;strong&gt;&lt;em&gt;unique&lt;/em&gt;&lt;/strong&gt; IP Address, like &lt;em&gt;108.161.228.70&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;However, in this article I want to do a more in-depth review about IP addresses and how the work.&lt;/p&gt;
&lt;p&gt;From a technical point of view and for reviewing purposes, it is worth remembering that IP Addresses (at least IPv4) are &lt;strong&gt;32-bit&lt;/strong&gt; addresses, because each number separated by each dot (called &lt;em&gt;octet&lt;/em&gt;) is an 8-bit number. Since IP Addresses have 4 octets, these together make a sum of 32-bits.&lt;/p&gt;
&lt;!-- raw HTML omitted --&gt;
&lt;p&gt;Since the first two octets make a sum of 16 bits, 2^16 yields a total of 65,536 networks. At the same time, the remaining 16 bits also yield a total of 65,536 different hosts. &lt;strong&gt;&lt;em&gt;But&lt;/em&gt;&lt;/strong&gt; these are 65,536 different hosts &lt;strong&gt;&lt;em&gt;per each&lt;/em&gt;&lt;/strong&gt; network.&lt;/p&gt;
&lt;p&gt;This raises a big issue because it makes it hard to decide how many bits in the IP address should be allocated to the network and how many bits should be allocated for the hosts, without wasting IP addresses. This is where &lt;strong&gt;subnet masks&lt;/strong&gt; come in.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Working With Zenoss Events</title>
      <link>https://aalvrz.me/posts/working-with-zenoss-events/</link>
      <pubDate>Fri, 25 Nov 2016 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/working-with-zenoss-events/</guid>
      <description>&lt;p&gt;Zenoss Events are among the most powerful and useful monitoring features that Zenoss Core provides. Many different types of events are &lt;strong&gt;automatically&lt;/strong&gt; generated by Zenoss when important scenarios occur for the devices being monitored.&lt;/p&gt;
&lt;h2 id=&#34;zenoss-event-architecture&#34;&gt;Zenoss Event Architecture&lt;/h2&gt;
&lt;p&gt;When an event arrives at Zenoss, it is parsed, associated with an event classification and then typically (but not always), it is inserted into the status table of the events database. Events can then be viewed by users using the Event Console of the Zenoss Graphical User Interface (GUI).&lt;/p&gt;
&lt;p&gt;The events system has the concept of active status events and historical events (two different database tables in the MySQL events database).&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://aalvrz.me/posts/working-with-zenoss-events/event_console.jpg&#34; alt=&#34;!Zenoss Core 4 Event Console&#34;&gt;&lt;/p&gt;
&lt;h3 id=&#34;understanding-event-classes&#34;&gt;Understanding Event Classes&lt;/h3&gt;
&lt;p&gt;Zenoss event classes are a simple organizational structure for the different types of events that Zenoss generates and receives. This organization is useful for driving alerting and reporting. You can, for example, create an alerting rule that sends you an email or pages you when the availability of a Web site or page is affected by filtering on the &lt;code&gt;/Status/Web&lt;/code&gt; event class^[2].&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>The Zenoss JSON API</title>
      <link>https://aalvrz.me/posts/the-zenoss-json-api/</link>
      <pubDate>Thu, 24 Nov 2016 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/the-zenoss-json-api/</guid>
      <description>&lt;p&gt;The &lt;a href=&#34;http://wiki.zenoss.org/Working_with_the_JSON_API&#34;&gt;Zenoss JSON API&lt;/a&gt; allows us to obtain very important information of what is going on in Zenoss, such as device information and events. This API can be queried using &lt;a href=&#34;https://curl.haxx.se/&#34;&gt;cURL&lt;/a&gt; or with some wrappers provided by Zenoss, available in languages such as Bashscript, Python, and Java.&lt;/p&gt;
&lt;p&gt;The API documentation can be downloaded &lt;a href=&#34;https://www.zenoss.com/sites/default/files/documentation/Zenoss_JSON_API_r5.0.4_d28.15.180_0.zip&#34;&gt;here&lt;/a&gt;. In the documentation you can see the available endpoints and methods that can be used to obtain the data we need.&lt;/p&gt;
&lt;p&gt;In this post I will cover how the Zenoss back-end JSON API works, and how the Zenoss&#39;s front-end (made using &lt;a href=&#34;https://www.sencha.com/products/extjs/&#34;&gt;ExtJS&lt;/a&gt;) interacts with it.&lt;/p&gt;
&lt;p&gt;~&amp;gt; Even though Zenoss calls its API a &lt;em&gt;JSON API&lt;/em&gt; (Simply because it returns data in JSON format), the API &lt;strong&gt;is not&lt;/strong&gt; &lt;a href=&#34;http://jsonapi.org/&#34;&gt;JSON API specification&lt;/a&gt; compliant.&lt;/p&gt;
&lt;h2 id=&#34;querying-the-api&#34;&gt;Querying the API&lt;/h2&gt;
&lt;p&gt;To see the API in action, we can begin by making a simple query using &lt;code&gt;cURL&lt;/code&gt;. Let&#39;s say we want to obtain all the available information of a specific device:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;curl -u &lt;span style=&#34;color:#d88200&#34;&gt;&amp;#34;admin:zenoss&amp;#34;&lt;/span&gt; -X POST -H &lt;span style=&#34;color:#d88200&#34;&gt;&amp;#34;Content-Type: application/json&amp;#34;&lt;/span&gt; -d &lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;{&amp;#34;action&amp;#34;: &amp;#34;DeviceRouter&amp;#34;, &amp;#34;method&amp;#34;: &amp;#34;getInfo&amp;#34;, &amp;#34;data&amp;#34;: [{&amp;#34;uid&amp;#34;: &amp;#34;/zport/dmd/Devices/Server/SSH/Linux/NovaHost/devices/$DEVICE_IP&amp;#34;}], &amp;#34;tid&amp;#34;: 1}&amp;#39;&lt;/span&gt; http://&lt;span style=&#34;color:#111&#34;&gt;$ZENOSS_HOST&lt;/span&gt;:8080/zport/dmd/device_router
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The above request will return the information of the device in JSON format, assuming that we replace &lt;code&gt;$ZENOSS_HOST&lt;/code&gt; with the IP address of our Zenoss server, and &lt;code&gt;$DEVICE_IP&lt;/code&gt; with the IP address of the device we want to query.&lt;/p&gt;
&lt;p&gt;This is all fine if all we need is querying the API and nothing else. But what if we really want to know &lt;strong&gt;&lt;em&gt;how&lt;/em&gt;&lt;/strong&gt; the API back-end works? How the endpoints are created? What are routers?&lt;/p&gt;
&lt;p&gt;This is what we are gonna learn next.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Using RRDTool in Zenoss</title>
      <link>https://aalvrz.me/posts/using-rrdtool-in-zenoss/</link>
      <pubDate>Tue, 22 Nov 2016 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/using-rrdtool-in-zenoss/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;http://oss.oetiker.ch/rrdtool/&#34;&gt;rrdtool&lt;/a&gt; is an awesome high performance data logging and graphing tool for time series data. Zenoss Core uses RRDTool to collect, monitor, and graph peformance data for devices.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;http://oss.oetiker.ch/rrdtool/stream-pop.png&#34; alt=&#34;RRD Tool&#34;&gt;&lt;/p&gt;
&lt;p&gt;However Zenoss Core comes with built-in helper wrappers around RRDTool that makes using it within Zenoss much easier. These source code files can be found in &lt;code&gt;$ZENHOME/Products/ZenRRD/&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;rrdutil&#34;&gt;RRDUtil&lt;/h2&gt;
&lt;p&gt;Located in &lt;code&gt;$ZENHOME/Products/ZenRRD/RRDUtil.py&lt;/code&gt;, this Python module contains many wrapper methods around the rrdtool library. These methods can help us write to, create new, and read &lt;code&gt;.rrd&lt;/code&gt; files using Python.&lt;/p&gt;
&lt;p&gt;We can easily import this module into our code, using the following import statement:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;Products.ZenRRD.RRDUtil&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;RRDUtil&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
    </item>
    
    <item>
      <title>IPMI &amp; Baseboard Management Controllers</title>
      <link>https://aalvrz.me/posts/ipmi-baseboard-management-controllers/</link>
      <pubDate>Fri, 18 Nov 2016 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/ipmi-baseboard-management-controllers/</guid>
      <description>&lt;p&gt;An &lt;strong&gt;Intelligent Platform Management Interface (IPMI)&lt;/strong&gt; is a set of interfaces that allow system administrators to manage and monitor systems, independently of the system&#39;s CPU, BIOS, and operating system.&lt;/p&gt;
&lt;p&gt;IPMI can also help manage computers that are unresponsive or powered off, by using a network connection to the &lt;strong&gt;hardware&lt;/strong&gt;, rather than to a operating system or login shell.&lt;/p&gt;
&lt;p&gt;More specifically, IPMI can help us monitor, obtain data, and perform tasks such as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;System temperature&lt;/li&gt;
&lt;li&gt;Voltages&lt;/li&gt;
&lt;li&gt;Fans&lt;/li&gt;
&lt;li&gt;Power supplies&lt;/li&gt;
&lt;li&gt;Chassis intrusion&lt;/li&gt;
&lt;li&gt;Perform recovery procedures&lt;/li&gt;
&lt;li&gt;System rebooting&lt;/li&gt;
&lt;li&gt;System powering&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;An IPMI sub-system consists of a main controller, called the baseboard management controller (BMC) and other management controllers distributed among different system modules that are referred to as &lt;em&gt;satellite controllers&lt;/em&gt;. The satellite controllers within the same chassis connect to the BMC via another system interface (not covered in this post) called Intelligent Platform Management Bus/Bridge (IPMB)&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Custom Markdown in Middleman</title>
      <link>https://aalvrz.me/posts/custom-markdown-in-middleman/</link>
      <pubDate>Thu, 17 Nov 2016 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/custom-markdown-in-middleman/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://middlemanapp.com/&#34;&gt;Middleman&lt;/a&gt; is an excellent static site generator written in Ruby. It is extremely practical for blogging as well, and it&#39;s the framework I am currently using for this blog.&lt;/p&gt;
&lt;p&gt;Unfortunately Middleman&#39;s &lt;a href=&#34;https://middlemanapp.com/basics/install/&#34;&gt;documentation&lt;/a&gt; is a bit unorganized and incomplete. I often find myself browsing through the &lt;a href=&#34;https://github.com/middleman/middleman&#34;&gt;source code&lt;/a&gt; to understand how to use or implement some custom features.&lt;/p&gt;
&lt;p&gt;For example, using &lt;a href=&#34;https://github.com/vmg/redcarpet&#34;&gt;redcarpet&lt;/a&gt; I wanted to be able to create some re-usable &amp;ldquo;markdown components&amp;rdquo; that I could use in my blog posts. Something like bootstrap alerts, so that I could re-use them without having to add HTML or any code to my markdown.&lt;/p&gt;
&lt;p&gt;And this post I am going to explain how to integrate this functionality into your blog using Middleman.&lt;/p&gt;
&lt;h2 id=&#34;creating-a-custom-renderer&#34;&gt;Creating a Custom Renderer&lt;/h2&gt;
&lt;p&gt;Middleman comes built in with a custom Redcarpet renderer which Middleman uses to parse the links and images (and possibly other things) in your blog&#39;s markdown. To be able to implement our custom markdown we need to create our own custom renderer, which should inherit from &lt;code&gt;Redcarpet::Render::HTML&lt;/code&gt;. However, the &lt;strong&gt;key&lt;/strong&gt; thing here is to actually inherit directly from &lt;a href=&#34;https://github.com/middleman/middleman/blob/master/middleman-core/lib/middleman-core/renderers/redcarpet.rb#L65&#34;&gt;Middleman&#39;s renderer&lt;/a&gt; (which of course, inherits from &lt;code&gt;Redcarpet::Render::HTML&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;To begin, we will create a &lt;code&gt;lib&lt;/code&gt; (if it doesn&#39;t exist) under our blog&#39;s directory and create a file named &lt;code&gt;markdown_helper.rb&lt;/code&gt; inside it. The initial contents of this helper will be:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-ruby&#34; data-lang=&#34;ruby&#34;&gt;&lt;span style=&#34;color:#00a8c8&#34;&gt;module&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;MarkdownHelper&lt;/span&gt;

  &lt;span style=&#34;color:#111&#34;&gt;require&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;middleman-core/renderers/redcarpet&amp;#39;&lt;/span&gt;

&lt;span style=&#34;color:#00a8c8&#34;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The required file above is what will allow us to inherit from Middleman&#39;s renderer.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Big O Notation - Omega &amp; Theta</title>
      <link>https://aalvrz.me/posts/big-o-notation-omega-theta/</link>
      <pubDate>Wed, 16 Nov 2016 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/big-o-notation-omega-theta/</guid>
      <description>&lt;p&gt;In a &lt;a href=&#34;https://aalvrz.me/posts/ruby-benchmarking-and-big-o-notation.html&#34;&gt;previous post&lt;/a&gt; I went over the basic and most common Big O notations along with respective common algorithms, and finally adding some Ruby benchmarks for each.&lt;/p&gt;
&lt;p&gt;However I did not cover some other very important concepts in Big O notation: &lt;strong&gt;Omega&lt;/strong&gt; and &lt;strong&gt;Theta&lt;/strong&gt;.&lt;/p&gt;
&lt;h2 id=&#34;understanding-omega&#34;&gt;Understanding Omega&lt;/h2&gt;
&lt;p&gt;The Omega symbol (Ω) represents a certain algorithm&#39;s &lt;em&gt;best-case&lt;/em&gt; asymptotic complexity. For example, let&#39;s take again a look at the &lt;a href=&#34;https://en.wikipedia.org/wiki/Binary_search_algorithm&#34;&gt;binary search algorithm&lt;/a&gt;:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://blog.penjee.com/wp-content/uploads/2015/04/binary-and-linear-search-animations.gif&#34; alt=&#34;Binary Search vs Linear Search&#34;&gt;&lt;/p&gt;
&lt;p&gt;Previously we determined that the Big O notation for this algorithm is &lt;em&gt;O(log n)&lt;/em&gt;. This represent the &lt;strong&gt;worst&lt;/strong&gt; asymptotic complexity that the algorithm can possibly have.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Ruby Benchmarking &amp; Big O Notation</title>
      <link>https://aalvrz.me/posts/ruby-benchmarking-and-big-o-notation/</link>
      <pubDate>Tue, 15 Nov 2016 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/ruby-benchmarking-and-big-o-notation/</guid>
      <description>&lt;p&gt;The Ruby &lt;a href=&#34;http://ruby-doc.org/stdlib-2.0.0/libdoc/benchmark/rdoc/Benchmark.html&#34;&gt;Benchmark&lt;/a&gt; library helps us to measure how long it takes for a block of code to run. Similar to when you subtract starting time and ending time in other languages such as Java.&lt;/p&gt;
&lt;p&gt;I was doing some &lt;a href=&#34;https://en.wikipedia.org/wiki/Big_O_notation&#34;&gt;Big O Notation&lt;/a&gt; reviewing with Ruby the other day and did some common algorithm implementations for each of the most common Big O notations, just for fun.&lt;/p&gt;
&lt;h2 id=&#34;using-benchmark&#34;&gt;Using Benchmark&lt;/h2&gt;
&lt;p&gt;To start benchmarking our code, we simply need to require &lt;code&gt;benchmark&lt;/code&gt; and use the methods provided by the &lt;code&gt;Benchmark&lt;/code&gt; module. For me, the most practical way is to use &lt;code&gt;Benchmark#bm&lt;/code&gt; method, where we pass a block of code we want to measure:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-ruby&#34; data-lang=&#34;ruby&#34;&gt;&lt;span style=&#34;color:#111&#34;&gt;require&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;benchmark&amp;#39;&lt;/span&gt;

&lt;span style=&#34;color:#00a8c8&#34;&gt;Benchmark&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;bm&lt;/span&gt; &lt;span style=&#34;color:#00a8c8&#34;&gt;do&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;|&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;x&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;|&lt;/span&gt;
  &lt;span style=&#34;color:#111&#34;&gt;x&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;report&lt;/span&gt; &lt;span style=&#34;color:#00a8c8&#34;&gt;do&lt;/span&gt;
    &lt;span style=&#34;color:#75715e&#34;&gt;# our code here&lt;/span&gt;
  &lt;span style=&#34;color:#00a8c8&#34;&gt;end&lt;/span&gt;

&lt;span style=&#34;color:#00a8c8&#34;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Inside the block we are using the &lt;code&gt;report&lt;/code&gt; method of the block&#39;s variable, which will basically do a separate benchmark for each report.&lt;/p&gt;
&lt;p&gt;However, we can improve this even more by adding a label to &lt;code&gt;report&lt;/code&gt; and a label width to &lt;code&gt;bm&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-ruby&#34; data-lang=&#34;ruby&#34;&gt;&lt;span style=&#34;color:#111&#34;&gt;require&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;benchmark&amp;#39;&lt;/span&gt;

&lt;span style=&#34;color:#00a8c8&#34;&gt;Benchmark&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;bm&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;20&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt; &lt;span style=&#34;color:#00a8c8&#34;&gt;do&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;|&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;x&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;|&lt;/span&gt;
  &lt;span style=&#34;color:#111&#34;&gt;x&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;report&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;my_algorithm&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;)&lt;/span&gt; &lt;span style=&#34;color:#00a8c8&#34;&gt;do&lt;/span&gt;
    &lt;span style=&#34;color:#75715e&#34;&gt;# our code here&lt;/span&gt;
  &lt;span style=&#34;color:#00a8c8&#34;&gt;end&lt;/span&gt;
&lt;span style=&#34;color:#00a8c8&#34;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Let&#39;s see it in action with some common algorithms.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Infinite Sequences in Ruby Using Enumerator</title>
      <link>https://aalvrz.me/posts/infinite-sequences-in-ruby-using-enumerator/</link>
      <pubDate>Mon, 14 Nov 2016 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/infinite-sequences-in-ruby-using-enumerator/</guid>
      <description>&lt;p&gt;The &lt;a href=&#34;http://ruby-doc.org/core-2.3.1/Enumerator.html&#34;&gt;Enumerator&lt;/a&gt; class in Ruby allows us to generate some very smooth and useful infinite sequences. For example, in some &lt;a href=&#34;https://projecteuler.net/&#34;&gt;Project Euler&lt;/a&gt; problems it is required to generate sequences without a specific limit. A good example of this is the &lt;em&gt;Highly Divisible Triangular Number&lt;/em&gt; problem:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be:

1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...

Let us list the factors of the first seven triangle numbers:

     1: 1
     3: 1,3
     6: 1,2,3,6
    10: 1,2,5,10
    15: 1,3,5,15
    21: 1,3,7,21
    28: 1,2,4,7,14,28

We can see that 28 is the first triangle number to have over five divisors.

What is the value of the first triangle number to have over five hundred divisors?
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;So first we would want to be able to generate a (infinite) sequence of &lt;a href=&#34;https://en.wikipedia.org/wiki/Triangular_number&#34;&gt;triangular numbers&lt;/a&gt; that we can use to do many programming operations, such as iterating over the sequence.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Modifying the Zenoss Infrastructure Grid</title>
      <link>https://aalvrz.me/posts/modifying-the-zenoss-infrastructure-grid/</link>
      <pubDate>Thu, 10 Nov 2016 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/modifying-the-zenoss-infrastructure-grid/</guid>
      <description>&lt;p&gt;Continuing from my previous post, where I explained &lt;a href=&#34;https://aalvrz.me/posts/modifying-the-zenoss-device-detail-bar.html&#34;&gt;how to modify the device detail bar from a ZenPack using ExtJS&lt;/a&gt;, in this post I will explain how we can modify the device list grid shown in the infrastructure page.&lt;/p&gt;
&lt;h2 id=&#34;the-infrastructure-grid&#34;&gt;The Infrastructure Grid&lt;/h2&gt;
&lt;p&gt;This is the table in the infrastructure page that shows all devices being monitored by Zenoss. Default columns include &lt;em&gt;device name&lt;/em&gt;, &lt;em&gt;device class&lt;/em&gt;, &lt;em&gt;IP address&lt;/em&gt;, &lt;em&gt;production state&lt;/em&gt;, and &lt;em&gt;events&lt;/em&gt;, as shown in the image below:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://aalvrz.me/posts/modifying-the-zenoss-infrastructure-grid/zenoss_device_grid.png&#34; alt=&#34;Zenoss Infrastructure Grid&#34;&gt;&lt;/p&gt;
&lt;p&gt;However it would be nice to also include the power status we added to the device detail bar in the previous post, maybe even add the ping status as well (why Zenoss doesn&#39;t do this by default is beyond me).&lt;/p&gt;
&lt;h2 id=&#34;devicepanelsjs&#34;&gt;DevicePanels.js&lt;/h2&gt;
&lt;p&gt;The source code for the grid is found in &lt;code&gt;$ZENHOME/Products/ZenUI/browser/resources/js/zenoss/DevicePanels.js&lt;/code&gt;. A quick glance at it and you will quickly find the definitions of the columns I mentioned earlier, defined in an array called &lt;code&gt;deviceColumns&lt;/code&gt;.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Modifying the Zenoss Device Detail Bar</title>
      <link>https://aalvrz.me/posts/modifying-the-zenoss-device-detail-bar/</link>
      <pubDate>Tue, 08 Nov 2016 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/modifying-the-zenoss-device-detail-bar/</guid>
      <description>&lt;p&gt;The Zenoss Core &lt;a href=&#34;https://www.sencha.com/products/extjs/&#34;&gt;&lt;strong&gt;ExtJS&lt;/strong&gt;&lt;/a&gt; graphic user interface is divided into many different components. In this post I will go over on how we can modify the device detail bar to display additional custom information for devices, by creating a custom ZenPack.&lt;/p&gt;
&lt;p&gt;Zenoss Core 4 uses ExtJS 4 JavaScript framework to manage all the user interface components. These components can be found in &lt;code&gt;$ZENHOME/Products/ZenUI3/browser/resources/js/zenoss&lt;/code&gt;, and as you would expect, the device detail bar component is also located there.&lt;/p&gt;
&lt;h2 id=&#34;the-device-detail-bar&#34;&gt;The Device Detail Bar&lt;/h2&gt;
&lt;p&gt;This is the detail bar located on the device view page which shows the device&#39;s icon, name, events, status, production state, and priority. The JavaScript source code for this component can be found in &lt;code&gt;DeviceDetailBar.js&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://aalvrz.me/posts/modifying-the-zenoss-device-detail-bar/device_detail_bar.png&#34; alt=&#34;Device Detail Bar&#34;&gt;&lt;/p&gt;
&lt;p&gt;However since we are going to &lt;strong&gt;&lt;em&gt;extend&lt;/em&gt;&lt;/strong&gt; this component through a ZenPack, we will not modify that source. Instead, we will add new code to use ExtJS to add our custom data displays.&lt;/p&gt;
&lt;h2 id=&#34;extending-the-component-through-zenpacks&#34;&gt;Extending The Component, Through ZenPacks&lt;/h2&gt;
&lt;p&gt;Let&#39;s assume we are starting with a freshly created ZenPack, which adds a new &lt;code&gt;power_status&lt;/code&gt; integer field to certain devices, according to its &lt;code&gt;zenpack.yaml&lt;/code&gt; file:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-yaml&#34; data-lang=&#34;yaml&#34;&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# ...&lt;/span&gt;

classes&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;
  CustomDevice&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;
    base&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;[&lt;/span&gt;zenpacklib.Device&lt;span style=&#34;color:#111&#34;&gt;]&lt;/span&gt;
    label&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt; Custom Device
    properties&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;
      power_status&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;
        type&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt; boolean

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;What we want is to display this value in the device&#39;s detail bar, similar to the device&#39;s ping status display.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Creating Zenoss ZenPack Daemons</title>
      <link>https://aalvrz.me/posts/creating-zenoss-zenpack-daemons/</link>
      <pubDate>Mon, 07 Nov 2016 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/creating-zenoss-zenpack-daemons/</guid>
      <description>&lt;p&gt;ZenPacks are powerful custom add-ons that can help us extend Zenoss&#39;s functionality. In this post I will go over on how to create a ZenPack that adds a custom daemon to the existing Zenoss daemons and runs on a configured cycle time to perform custom tasks. We will achieve this by creating the ZenPack using &lt;a href=&#34;http://zenpacklib.zenoss.com/en/latest/index.html&#34;&gt;&lt;strong&gt;zenpacklib&lt;/strong&gt;&lt;/a&gt;, but it is also possible to create it from the Zenoss user interface.&lt;/p&gt;
&lt;h2 id=&#34;about-zenpacklib&#34;&gt;About zenpacklib&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;zenpacklib&lt;/strong&gt; is a Python library developed by the Zenoss team to facilitate the process of creating ZenPacks, specially ZenPacks that deal with modeling and monitoring devices and components. Most of the newer ZenPacks that are being released are now being built with zenpacklib.&lt;/p&gt;
&lt;p&gt;We can obtain zenpacklib by running the following commands:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;wget http://zenpacklib.zenoss.com/zenpacklib.py
chmod 755 zenpacklib.py
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This will download the zenpacklib Python library and give it executable permissions.&lt;/p&gt;
&lt;h2 id=&#34;creating-the-zenpack&#34;&gt;Creating the ZenPack&lt;/h2&gt;
&lt;p&gt;Using the zenpacklib file we just downloaded, we proceed to create a new fresh ZenPack:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;./zenpacklib.py create ZenPacks.&amp;lt;your_namespace&amp;gt;.&amp;lt;zenpack_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This will create the ZenPack base directory with the necessary base files.&lt;/p&gt;
&lt;p&gt;Now we go into this directory to begin.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;cd ZenPacks.&amp;lt;your_namespace&amp;gt;.&amp;lt;zenpack_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;creating-the-zenpack-daemon&#34;&gt;Creating the ZenPack Daemon&lt;/h2&gt;
&lt;p&gt;Our custom daemon declaration will be located in a directory named &lt;code&gt;daemons&lt;/code&gt;, inside our ZenPack directory:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;mkdir ZenPacks.&amp;lt;your_namespace&amp;gt;.&amp;lt;zenpack_name&amp;gt;/&amp;lt;your_namespace&amp;gt;/&amp;lt;zenpack_name&amp;gt;/daemons
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Here we will create a new Bashscript file with the name of our daemon. In this case we will name it &lt;code&gt;mydaemon&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#! /usr/bin/env bash
&lt;/span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;&lt;/span&gt;
&lt;span style=&#34;color:#111&#34;&gt;DAEMON_NAME&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#34;mydaemon&amp;#34;&lt;/span&gt;

. &lt;span style=&#34;color:#111&#34;&gt;$ZENHOME&lt;/span&gt;/bin/zenfunctions

&lt;span style=&#34;color:#111&#34;&gt;MYPATH&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;`&lt;/span&gt;python -c &lt;span style=&#34;color:#d88200&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;import os.path; print os.path.realpath(&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;$0&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;)&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;`&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;THISDIR&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;`&lt;/span&gt;dirname &lt;span style=&#34;color:#111&#34;&gt;$MYPATH&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;`&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;PRGHOME&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;`&lt;/span&gt;dirname &lt;span style=&#34;color:#111&#34;&gt;$THISDIR&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;`&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;PRGNAME&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;$DAEMON_NAME&lt;/span&gt;.py &lt;span style=&#34;color:#111&#34;&gt;CFGFILE&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;$CFGDIR&lt;/span&gt;/&lt;span style=&#34;color:#111&#34;&gt;$DAEMON_NAME&lt;/span&gt;.conf

generic &lt;span style=&#34;color:#d88200&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#111&#34;&gt;$@&lt;/span&gt;&lt;span style=&#34;color:#d88200&#34;&gt;&amp;#34;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Once the ZenPack is installed, files under this &lt;code&gt;daemons&lt;/code&gt; directory will become executable (&lt;code&gt;chmod 0755&lt;/code&gt;), a symlink to the file will be created in &lt;code&gt;$ZENHOME/bin&lt;/code&gt;, and a configuration file will be generated in &lt;code&gt;$ZENHOME/etc/&amp;lt;daemon_name&amp;gt;.conf&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; If you created your ZenPack using the Zenoss user interface, the &lt;code&gt;daemons&lt;/code&gt; directory will also be automatically created, and will contain an example daemon file named &lt;code&gt;zenexample&lt;/code&gt; with code similar to the one above. In this case you should simply replace the necessary values.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Monitoring CPU Utilization in Zenoss</title>
      <link>https://aalvrz.me/posts/monitoring-cpu-utilization-in-zenoss/</link>
      <pubDate>Fri, 04 Nov 2016 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/monitoring-cpu-utilization-in-zenoss/</guid>
      <description>&lt;p&gt;While taking a look at the CPU Utilization graphs offered Zenoss Core&#39;s &lt;a href=&#34;http://wiki.zenoss.org/ZenPack:Linux_Monitor&#34;&gt;Linux Monitor ZenPack&lt;/a&gt; (v1.2.1), I noticed that the percentage values for &lt;em&gt;Idle&lt;/em&gt; were ridiculously high:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://aalvrz.me/posts/monitoring-cpu-utilization-in-zenoss/cpu_utilization_1.jpg&#34; alt=&#34;High Idle CPU Utilization&#34;&gt;&lt;/p&gt;
&lt;p&gt;This made sense since this particular device contains 16 cores. However, this then means that the monitoring template isn&#39;t really taking this into consideration, and instead just spits out the total value from all cores.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Zenoss Monitoring Template Data Points</title>
      <link>https://aalvrz.me/posts/zenoss-monitoring-template-data-points/</link>
      <pubDate>Thu, 03 Nov 2016 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/zenoss-monitoring-template-data-points/</guid>
      <description>&lt;p&gt;&lt;em&gt;Content from this post is mostly obtained from &lt;strong&gt;Zenoss Core Administration guide&lt;/strong&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;In Zenoss Core &lt;strong&gt;monitoring templates&lt;/strong&gt;, data sources can return data for one or more performance metrics. Each metric retrieved by a data source is represented
by a &lt;strong&gt;data point&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;When creating a data point, there are some important fields that we can define for our data point:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Name:&lt;/strong&gt; Displays the name you entered in the &lt;em&gt;Add a New DataPoint&lt;/em&gt; dialog.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;RRD Type:&lt;/strong&gt; Specify the RRD data source type to use for storing data for this data point. (Zenoss Core uses RRDTool to store performance data.) Available options are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;COUNTER:&lt;/strong&gt; Saves the rate of change of the value over a step period. This assumes that the value is always
increasing (the difference between the current and the previous value is greater than 0). Traffic counters on a
router are an ideal candidate for using COUNTER.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;GAUGE:&lt;/strong&gt; Does not save the rate of change, but saves the actual value. There are no divisions or calculations.
To see memory consumption in a server, for example, you might want to select this value.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;DERIVE:&lt;/strong&gt; Same as COUNTER, but additionally allows negative values. If you want to see the rate of change
in free disk space on your server, for example, then you might want to select this value.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;ABSOLUTE:&lt;/strong&gt; Saves the rate of change, but assumes that the previous value is set to 0. The difference between
the current and the previous value is always equal to the current value. Thus, ABSOLUTE stores the current
value, divided by the step interval.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Create Command:&lt;/strong&gt; Enter an RRD expression used to create the database for this data point. If you do not enter
a value, then the system uses a default applicable to most situations. For details about the &lt;!-- raw HTML omitted --&gt;rrdcreate&lt;!-- raw HTML omitted --&gt; command, go &lt;a href=&#34;http://oss.oetiker.ch/rrdtool/doc/rrdcreate.en.html&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;RRD Minimum:&lt;/strong&gt; Enter a value. Any value received that is less than this number is ignored.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;RRD Maximum:&lt;/strong&gt; Enter a value. Any value received that is greater than this number is ignored.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;data-point-aliases&#34;&gt;Data Point Aliases&lt;/h2&gt;
&lt;p&gt;Performance reports pull information from various data points that represent a metric. The report itself knows which
data points it requires, and which modifications are needed, if any, to put the data in its proper units and format.&lt;/p&gt;
&lt;p&gt;The addition of a data point requires changing the report.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://aalvrz.me/posts/zenoss-monitoring-template-data-points/cpu_report.jpg&#34; alt=&#34;CPU Utilization Report&#34;&gt;&lt;/p&gt;
&lt;p&gt;To allow for more flexibility in changes, some reports use &lt;em&gt;data point aliases&lt;/em&gt;. Data point aliases group data points so
they can be more easily used for reporting. In addition, if the data points return data in different units, then the plugin
can normalize that data into a common unit.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Triggering Commands From Events in Zenoss</title>
      <link>https://aalvrz.me/posts/triggering-commands-from-events-in-zenoss/</link>
      <pubDate>Mon, 31 Oct 2016 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/triggering-commands-from-events-in-zenoss/</guid>
      <description>&lt;p&gt;In Zenoss Core 4, we can configure some &lt;strong&gt;&lt;em&gt;email&lt;/em&gt;&lt;/strong&gt; notifications that produce and send emails based on conditions defined in a trigger, when an event is created.&lt;/p&gt;
&lt;p&gt;Additionally, Zenoss Core 4 also provides &lt;strong&gt;&lt;em&gt;command&lt;/em&gt;&lt;/strong&gt; type notifications that allow us to execute commands in the Zenoss machine when the trigger criterias are met.&lt;/p&gt;
&lt;p&gt;For example, let&#39;s say we want to execute a script everytime we ping a device and get no response. This scenario would involve the following:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The device is suddenly down.&lt;/li&gt;
&lt;li&gt;Zenoss pings the device and gets no response.&lt;/li&gt;
&lt;li&gt;The device status is then changed to &lt;em&gt;DOWN&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;An Event with an event class of &lt;code&gt;/Status/Ping&lt;/code&gt; and a severity of &lt;em&gt;Critical&lt;/em&gt; is created.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;With this information, we can create a trigger that will represent this exact scenario. Moreover, we can configure a command notification to be executed when this trigger is fired.&lt;/p&gt;
&lt;h2 id=&#34;configuring-a-trigger&#34;&gt;Configuring a Trigger&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;Navigate to Events &amp;gt; Triggers&lt;/li&gt;
&lt;li&gt;Create a new trigger.&lt;/li&gt;
&lt;li&gt;Add the rules that represent the scenario mentioned before. In this case, all of these rules must apply:&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;img src=&#34;https://aalvrz.me/posts/triggering-commands-from-events-in-zenoss/edit_trigger.png&#34; alt=&#34;Edit Trigger&#34;&gt;&lt;/p&gt;
&lt;p&gt;=&amp;gt; Because we want to make sure the device is truly &lt;em&gt;DOWN&lt;/em&gt;, and has been so for quite a while, we also want to add a condition that checks that the event count is greater than a certain number, only then the trigger will be fired, and consequently, the command.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Keystone Interface in Juju Charms</title>
      <link>https://aalvrz.me/posts/keystone-interface-in-juju-charms/</link>
      <pubDate>Fri, 28 Oct 2016 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/keystone-interface-in-juju-charms/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://jujucharms.com/docs/1.18/authors-interfaces&#34;&gt;Juju Charms interfaces&lt;/a&gt; make possible the interaction and exchange of data between services deployed by Juju. In this post I will explain how we can use the Keystone interface to make our custom charm service comunicate with the Keystone service within a Juju environment.&lt;/p&gt;
&lt;p&gt;In the end, what we really want to achieve, is to link both services so that they can exchange data, using a Juju command:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;juju add-relation keystone myservice&lt;/code&gt;&lt;/p&gt;
&lt;h2 id=&#34;juju-relations&#34;&gt;Juju Relations&lt;/h2&gt;
&lt;p&gt;Juju relations operate behind the concept that one service provides something, while another service requires it, and the interaction between the services is done through an &lt;strong&gt;interface&lt;/strong&gt;. Since we want to interact with Keystone, this means that we need to use a suitable keystone interface that allows us to get what we need, the &lt;em&gt;keystone Identity data&lt;/em&gt;. For this, we use the &lt;strong&gt;&lt;a href=&#34;https://git.launchpad.net/~canonical-is/charms/+source/interface-keystone-admin&#34;&gt;keystone-admin interface&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;With this in mind, we configure our charm to require this relation and interface in &lt;code&gt;metadata.yaml&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-yaml&#34; data-lang=&#34;yaml&#34;&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# ...&lt;/span&gt;
requires&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;
  identity-admin&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;
    interface&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt; keystone-admin
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
    </item>
    
    <item>
      <title>Zenoss Renderers</title>
      <link>https://aalvrz.me/posts/zenoss-renderers/</link>
      <pubDate>Thu, 27 Oct 2016 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/zenoss-renderers/</guid>
      <description>&lt;p&gt;Zenoss makes use of some very interesting graphical components called renderers. These are used to manipulate the way data is shown in the Zenoss user interface.&lt;/p&gt;
&lt;p&gt;For example, a value of &lt;em&gt;total bytes used&lt;/em&gt; could be 6080626688 in bytes, which is a very high number and doesn&#39;t really convey much meaning. However, we can use a built-in Zenoss renderer called &lt;code&gt;bytesString&lt;/code&gt; which will convert this value in bytes to the closest representation:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://aalvrz.me/posts/zenoss-renderers/zenoss_renderers.png&#34; alt=&#34;Zenoss Renderers&#34;&gt;&lt;/p&gt;
&lt;p&gt;As we can see, this is a much better and meaningful way of displaying the data.&lt;/p&gt;
&lt;p&gt;The built-in Zenoss renderers and source code can be found in &lt;code&gt;$ZENHOME/Products/ZenUI3/browser/resources/js/zenoss/Renderers.js&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;They are a list of registered Javascript functions that can be assigned in our YAML definitions file by adding the &lt;code&gt;renderer&lt;/code&gt; property. For example:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-yaml&#34; data-lang=&#34;yaml&#34;&gt;HardDisk&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;
  base&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;[&lt;/span&gt;zenpacklib.Component&lt;span style=&#34;color:#111&#34;&gt;]&lt;/span&gt;
  label&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt; Hard Disk
  properties&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;
     location&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;
        label&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt; Location

     capacity&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;
        label&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt; Capacity

     raid_name&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;
        label&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt; Raid Name

     raid_level&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;
        label&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt; Raid Level

     status&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt;
        label&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt; Status
        renderer&lt;span style=&#34;color:#111&#34;&gt;:&lt;/span&gt; Zenoss.render.pingStatus
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;Zenoss.render.pingStatus&lt;/code&gt; is one of the default renderers that come built-in within Zenoss Core 4, similar to &lt;code&gt;Zenoss.render.bytesString&lt;/code&gt;.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Changing Zenoss Dashboard Portlets Using CLI</title>
      <link>https://aalvrz.me/posts/changing-zenoss-dashboard-portlets-using-cli/</link>
      <pubDate>Wed, 26 Oct 2016 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/changing-zenoss-dashboard-portlets-using-cli/</guid>
      <description>&lt;p&gt;The Zenoss &lt;a href=&#34;http://wiki.zenoss.org/ZenPack:Dashboard&#34;&gt;ZenPacks.zenoss.Dashboard&lt;/a&gt; ZenPack adds a very nice and new dashboard to our Zenoss Core 4 deployment, replacing the old default dashboard that comes with the installation.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;http://wiki.zenoss.org/images/0/01/Separate_dashboard.png&#34; alt=&#34;ZenPack Dashboard&#34;&gt;&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Configuring a local apt repository</title>
      <link>https://aalvrz.me/posts/configuring-a-local-apt-repository/</link>
      <pubDate>Mon, 17 Oct 2016 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/configuring-a-local-apt-repository/</guid>
      <description>&lt;p&gt;Setting up a local apt repository can allow you to use &lt;code&gt;apt-get install&lt;/code&gt; command to install your own packages. This is a better approach than using &lt;code&gt;dpkg -i&lt;/code&gt; because apt will fetch and install the required dependencies (which should also be located in your local repository) in an &lt;strong&gt;offline&lt;/strong&gt; fashion.&lt;/p&gt;
&lt;h2 id=&#34;add-local-repository-to-sources&#34;&gt;Add Local Repository to Sources&lt;/h2&gt;
&lt;p&gt;First we need to add our local repository to &lt;code&gt;apt&lt;/code&gt;&#39;s list of source repositories, this can be found in &lt;code&gt;/etc/apt/sources.list&lt;/code&gt;. To add our local repository, we add the following line at the top of the file:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;/path/to/local-deb-repo/ ./
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Where &lt;em&gt;local-deb-repo&lt;/em&gt; is the name of our local repository directory.&lt;/p&gt;
&lt;h2 id=&#34;add-debian-packages&#34;&gt;Add Debian Packages&lt;/h2&gt;
&lt;p&gt;Now we create local repository&#39;s directory just like we specified it in the previous step:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;mkdir /path/to/local-deb-repo/
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Once we&#39;ve done that, we can proceed to put the Debian package files (&lt;code&gt;.deb&lt;/code&gt;) and their dependencies inside the directory.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Managing Debian Package Dependencies</title>
      <link>https://aalvrz.me/posts/managing-debian-package-dependencies/</link>
      <pubDate>Fri, 14 Oct 2016 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/managing-debian-package-dependencies/</guid>
      <description>&lt;p&gt;In a previous post, I talked about &lt;a href=&#34;2016-10-11-debian-packaging-in-ubuntu.html&#34;&gt;building a simple Debian package in Ubuntu&lt;/a&gt;, however I did not go into details on how to manage the dependencies that your Debian package might require. In this post I will cover exactly that.&lt;/p&gt;
&lt;h2 id=&#34;dpkg-and-dependencies&#34;&gt;dpkg and Dependencies&lt;/h2&gt;
&lt;p&gt;Previously we installed our package using the &lt;!-- raw HTML omitted --&gt;dpkg -i&lt;!-- raw HTML omitted --&gt; command. However, the problem with &lt;code&gt;dpkg&lt;/code&gt; is that by itself, it is not capable of managing repositories. Therefore, higher level tools (such as &lt;code&gt;apt-get&lt;/code&gt;) are required to fetch dependencies from repositories.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;dkpg is only the core tool that installs/removes/configures packages, taking care of dependencies and other factors. apt-get and aptitude are tools that manage repositories, download data from them, and use dkpg to install/remove packages from them. This means, that apt-get and aptitude can resolve dependencies and get required packages from repository, but dpkg cannot, because it knows nothing about repositories.&lt;/p&gt;
&lt;/blockquote&gt;</description>
    </item>
    
    <item>
      <title>Creating Python Packages</title>
      <link>https://aalvrz.me/posts/creating-python-packages/</link>
      <pubDate>Thu, 13 Oct 2016 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/creating-python-packages/</guid>
      <description>&lt;p&gt;For a project involving Zenoss Core 4 and a HaaS solution maintained by another team, we needed a module to interact with the &lt;a href=&#34;http://wiki.zenoss.org/Working_with_the_JSON_API&#34;&gt;Zenoss JSON API&lt;/a&gt; to get the list of events for specific devices. Browsing around I found this &lt;a href=&#34;https://github.com/iamseth/python-zenoss&#34;&gt;python-zenoss&lt;/a&gt; module to work with the Zenoss JSON API. However I was experiencing some issues when installing it, so I decided to create my own Python package to provide a different way to interact with the Zenoss JSON API according to our specific needs.&lt;/p&gt;
&lt;p&gt;The package would be installed locally using &lt;code&gt;pip&lt;/code&gt;, and all its functionality should be easily accessible using &lt;code&gt;from&lt;/code&gt; and &lt;code&gt;import&lt;/code&gt; commands in Python.&lt;/p&gt;
&lt;p&gt;To start working in our package we will create a base directory. The directory&#39;s name will resemble our package&#39;s name. For naming, we should following these guidelines:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;All lowercase&lt;/li&gt;
&lt;li&gt;Underscore-separated or no word separators at all (don’t use hyphens)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The package contents are the following:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;my_api/
├── __init__.py
├── api.py
└── setup.py
&lt;/code&gt;&lt;/pre&gt;</description>
    </item>
    
    <item>
      <title>Debian Packaging in Ubuntu</title>
      <link>https://aalvrz.me/posts/debian-packaging-in-ubuntu/</link>
      <pubDate>Tue, 11 Oct 2016 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/debian-packaging-in-ubuntu/</guid>
      <description>&lt;p&gt;Debian packaging is a nice way to organize our software so that it can be installed and uninstalled with more ease. In this post we will go through the basics of creating a simple Debian package in Ubuntu 14.04 LTS.&lt;/p&gt;
&lt;h2 id=&#34;package-source--structure&#34;&gt;Package Source &amp;amp; Structure&lt;/h2&gt;
&lt;p&gt;We will first create our working space for our package along with the necessary basic structure needed. For this example, we will create a directory for our package source, using the package title and 3 digit versioning in the directory&#39;s title:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;mkdir mypackage-1.0.0
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Inside our package, we will need a directory where we will hold the control files that give the Debian package the desired behavior:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;cd mypackage-1.0.0
mkdir DEBIAN
touch DEBIAN/control
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This &lt;code&gt;control&lt;/code&gt; file will describe our package to the Debian package manager (&lt;code&gt;dpkg&lt;/code&gt;). Inside, we can specify information about the package such as version, architecture, dependencies, maintainer, etc, as shown below:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Package: mypackage
Version: 1.0-0
Section: base
Priority: optional
Architecture: all
Depends: python2.7
Maintainer: Andres Alvarez &amp;lt;myemail@gmail.com&amp;gt;
Description: A new and improved C++ Compiler
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;With this basic setup, we now have a basic working package that can be handled by the Debian package manager, albeit, with no contents.&lt;/p&gt;</description>
    </item>
    
  </channel>
</rss>