Spent about 2 days setting Zabbix 3.0.4 on Debian, smooth sailing for the most part. One error almost made me want to switch to other monitoring solution, almost 2 days spent searching and trying to fix one silly error. I will just put source code of Zabbix where that error occurs for anyone else that’s getting it.

zabbix-3.0.4\src\zabbix_server\trapper\active.c

result =
#if defined(HAVE_POLARSSL) || defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL)
    DBselect(
        "select hostid,status,tls_accept,tls_issuer,tls_subject,tls_psk_identity"
        " from hosts"
        " where host='%s'"
            " and status in (%d,%d)"
            " and flags<>%d"
            " and proxy_hostid is null",
        host_esc, HOST_STATUS_MONITORED, HOST_STATUS_NOT_MONITORED, ZBX_FLAG_DISCOVERY_PROTOTYPE);
#else
    DBselect(
        "select hostid,status,tls_accept"
        " from hosts"
        " where host='%s'"
            " and status in (%d,%d)"
            " and flags<>%d"
            " and proxy_hostid is null",
        host_esc, HOST_STATUS_MONITORED, HOST_STATUS_NOT_MONITORED, ZBX_FLAG_DISCOVERY_PROTOTYPE);
#endif
if (NULL != (row = DBfetch(result)))
{
    /* Code removed */
}
else
{
    zbx_snprintf(error, MAX_STRING_LEN, "host [%s] not found", host);

    /* Code removed */
}

 

zabbix-3.0.4\frontends\php\include\defines.inc.php

define('HOST_STATUS_MONITORED',        0);
define('HOST_STATUS_NOT_MONITORED',    1);
define('ZBX_FLAG_DISCOVERY_PROTOTYPE',    0x2);

 

Lesson learned, if project is open source and is throwing errors, look at source code. Googling – 1.5days, source code – 5min.

 

I found myself opening command promp or powershell more and more often. There is one small trick that speeds it up: in explorer (to start explorer you can use win + e) press alt + d this will give focus to address bar, then type cmd  and press enter. This will start command promp at that path. This is fine, but I need to run command promp as administrator, it can be done: File –> Open command promp –> Open command promp as administrator or you can just press Alt, F, M, A. I don’t like this way, I’m so used to pressing alt + d that I wanted to type cmda press enter and start command promp as admin. Its quite trivial application, hardest part is to figure out how to start command prompt at specific folder but google can help with that. Before using first solution that I found online I decided to take a look how Windows start it when you go with above mention method through File menu. It looks like MS uses undocumented trick, if you push path when starting cmd it will pop it and start in it. None of the solutions found on internet mention this way.

image

 

   /K     Run Command and then return to the CMD prompt.
          This is useful for testing, to examine variables
   /S    Strip " quote characters from command.
         If command starts with a quote, the first and last quote chars in command
         will be removed, whether /s is specified or not.

Source:http://ss64.com/nt/cmd.html

Pushd - Stores the name of the current directory for use by the popd command before changing the current directory to the specified directory.

Syntax:pushd [Path]

Source:https://technet.microsoft.com/en-us/library/bb490978.aspx

 

var p = new Process
{
    StartInfo =
    {
        FileName = @"C:\Windows\system32\cmd.exe",
        UseShellExecute = true,
        Verb = "runas",
        Arguments = $"/s /k pushd \"{Directory.GetCurrentDirectory()}\" "
    }
};

p.Start();

Application itself is done, but there is still one issue.

I have 64bit Windows and I want to start 64 bit cmd, if I compile with:

  1. Any CPU or x86 and run application, it will start 32bit cmd from C:\Windows\SysWOW64\cmd.exe
  2. x64 and run application, it will start 64bit cmd from C:\Windows\system32\cmd.exe

Cmd path doesn’t really matter, Windows does file redirection based on how app is compiled. More on that on MSDN.

 

Source and binaries

 

 

Some preparation steps must be done outside VS:

  1. Add remote branch:

git remote add <branchName> <branchUrl>

2. Download new branch:

git fetch <branchName>

image

 

Now in VS Braches we have new remote with branches. We will merge issue_28 branch that fixes small bug.

image

We can right click it and checkout, to test changes in pull request.

 

When changes are ready to be merged, double click on our master branch, then right click it and select Merge From.

image

 

Now in Synchronization tab we have all merged changes, press push to finish merge and send all changes to server.

image

I have stand up table for about 1.5 years and I had this idea to “improve” it for some time now and finally for Christmas bought Arduino Uno starter kit.

For first version it simply measures tables height and shows charts. That’s it.

This is pre alpha version and I am using huge soap box with duct tape attached at the bottom of table.

WP_20160109_12_08_52_Pro

 

Inside is not much fancier just Arduino Uno with distance sensor (HC-SRO4 Ultrasonic Sensor).

WP_20160109_12_09_54_Pro

 

Simple dashboard to track my goal, which currently is 30% of time to be standing. For charts, I used Metro UI charts.

Application

 

Current Arduino project source code is really good example of how easy it is to communicate with computer. Just putting it there, maybe it will motivate others to start their Arduino projects.

#define echoPin 7 // Echo Pin
#define trigPin 8 // Trigger Pin

String command;   // for incoming serial data

long duration, distance; // Duration used to calculate distance

void setup()
{
    Serial.begin(9600);
    pinMode(trigPin, OUTPUT);
    pinMode(echoPin, INPUT);
}

void loop()
{
    if (Serial.available() > 0)
    {
        command = Serial.readString();
        if (command == "1")
        {
            Serial.println(getHeight());
        }
    }
}

long getHeight()
{
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);
    duration = pulseIn(echoPin, HIGH);
    return duration / 58.2;
}

C# sample code which will send command to Arduino and when it responds will print distance. Rinse and repeat.

using System;
using System.IO.Ports;
 
namespace ArdApp
{
    class Program
    {
        private const string GetHeight = "1";
 
        private static SerialPort _serialPort;
 
        static void Main()
        {
            _serialPort = new SerialPort(portName: "COM3", baudRate: 9600);
            _serialPort.DataReceived += serialPort_DataReceived;
 
            _serialPort.Write(GetHeight);
        }
 
        private static void serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            var height = Int32.Parse(_serialPort.ReadLine());
            Console.WriteLine($"{DateTime.Now} - {height}");
 
            if (_serialPort.IsOpen == false)
            {
                _serialPort.Open();
            }
 
            _serialPort.Write(GetHeight);
        }
    }
}

And if you don’t know port name, got to “Device Manager” and look under Ports. Baund rate should match one specified in Arduino application source.

image

 

Well this is just a beginning, I have more plans how to improve it by adding more sensors and extensions to it. Will see if Arduino Uno can handle what I have in mind.

Project source code.

Angular allows to display views when they are pre-rendered in page or lazy load them on navigation. I personally don’t like pre-rendering all views in single page, because it can get really big quite fast. Rendering Razor views on server isn’t that easy out of the box, luckily there is Nuget package Westwind.Web.Mvc.

Steps to configure Razor view rendering on server:

1. Install Westwind.Web.Mvc.

2. Set up Angular routing, I am using ui-router.

$stateProvider
    .state('app', {
        url: '/app',
        abstract: true,
        templateUrl: 'views/home/base'
    }).state('app.index', {
        url: '/index',
        templateUrl: 'views/home/index'
    })

3. Create route for loading views.

routes.MapRoute(
    name: "Views",
    url: "views/{ctrl}/{view}",
    defaults: new { controller = "Views", action = "get" });

4. Create view rendering controller, which is basically one-liner:

public class ViewsController : Controller
{

    public ActionResult Get(string ctrl, string view)
    {
        var path = $"~/views/{ctrl}/{view}.cshtml";

        return Content(ViewRenderer.RenderPartialView(path), "text/html", Encoding.UTF8);
    }

}

And that’s it. There is one downside of this quick demo, if partial view has other partial views inside, they will not be rendered and exception will be thrown. Exception will say that it didn’t find that inner partial view, because we haven’t specified request context and controller and Razor view engine don’t know where to look for it.

 

Simple project that I put together for demo.