Tuesday, July 5, 2016

Simple Zabbix reporter in Pythom

After reading this post, I've created a simple Zabbix sender in Python. This sender works perfectly with Zabbix 3.0.
Code is following:

1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class ZabbixReporter:
    def __init__(self, server, max_err_count=10):
        self.max_err_count = max_err_count
        self.socket_err_threshold = max_err_count
        self.server = server

    def report_to_zabbix(self, zhost, key, value):
        data = "<req><host>{host}</host><key>{key}</key><data>{value}</data>".format(host=b64encode(zhost),
                                                                                     key=b64encode(key),
                                                                                     value=b64encode(value))
        try:
            s = socket.socket(
                socket.AF_INET, socket.SOCK_STREAM)
            s.connect((self.server, 10051))
            s.send(data)
            s.close()
            self.reset_err_count()
        except Exception as e:
            print e
            self.register_error()

    def reset_err_count(self):
        self.socket_err_threshold = self.max_err_count

    def register_error(self):
        self.socket_err_threshold -= 1
        if self.socket_err_threshold <= 0:
            raise Exception("Failed to send data!")
        else:
            print "{} attempts left".format(self.socket_err_threshold)

Friday, January 8, 2016

How to make Vim highlight Gradle syntax

This instruction was tested by me in OS X:

1. Edit/create file ~/.vimrc. Make sure that it contains following lines:
filetype plugin indent on

syntax on

2. Download Groovy for Vim configuration from here and save it to $HOME/.vim/syntax/ folder (create if missing): http://www.vim.org/scripts/script.php?script_id=945

3. Add following line to $HOME/.vim/filetype.vim file (create is missing): 
au BufNewFile,BufRead *.gradle  setf groovy 

4. Re-open your Vim

Wednesday, January 6, 2016

OS X - setting up "Jump to file" filters in IntellijIDEA 15

I've recently faced a problem with setting up file type filters in "Jump to file" dialog in IntellijIDEA 15 on Mac. Whenever I was trying to uncheck any of file extension checkboxes in the list, the dialog was disappearing.

Solved by clicking on any checkbox holding "Control" button once to make it focused, and then use it regular way.

Tuesday, August 11, 2015

Oracle VirtualBox (Windows) - Ubuntu VM does not startup after upgrade

I have recently upgraded VirtualBox to 4.3.30, and my Xubuntu instance failed to load.
The error was following:

NtCreateFile(\Device\VBoxDrvStub) failed: 0xc000000034
STATUS_OBJECT_NAME_NOT_FOUND (0 retries)

Driver is probably stuck stopping/starting. Try 'sc.exe query vboxdrv' to get more information about its state. Rebooting may actually help. (rc=-101)

Make sure the kernel module has been loaded successfully.


PC restart did not help. After browsing several forums, I've found a solution that did work for me.

Go to C:\Program Files\Oracle\VirtualBox\drivers\vboxdrv directory, right click on VBoxDrv.inf, and select "Install".

Then try to run following in console: "sc start vboxdrv". For me it displayed a message saying that vboxdrv is already running.

No restart of VirtualBox needed. Try to startup the VM. 

Wednesday, December 18, 2013

MySQL: Column alias on negative value selection

Whenever you select a negative value from MySQL table, "-" will become a part of the field name returned in a result set. 

For example, we have following statement:

select id from MY_TABLE;
It will return a result with field name "id".

select -id from MY_TABLE;
will return a result with field name "-id".

select -custom.id from MY_TABLE custom;
will also include table alias name and return a result with field name "-custom.id".
In such case you should use "as %FIELD_NAME%" to be sure that you will have same field name:
select -custom.id as id from MY_TABLE custom;

Monday, July 15, 2013

Delete a file with special characters in Linux

Sometimes you can put command line parameters in wrong order, and have a file name starting with "--" as a result. If you'll try to use rm <file name> it will fail because it will assume that you are providing a flag to rm command.
In this case, use following command:
rm -- <file name>

Wednesday, June 5, 2013

Change ownership of symbolic link

To change ownership of a symbolic link, use flag -h:
chown -h {USER_NAME}:{GROUP_NAME} {SYMLINK_NAME}