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.