Friday, March 25, 2016

Python 3- Send Data to Zabbix Server

Following is method to send data to zabbix (2.4.6)  server written in python 3.

Corresponding Item key should be configured as zabbix trapper on zabbix server to successfully process this request.

Zabbix data is a json in following format.

{
  "request":"sender data",
  "data":[
     {
       "host":"hostName",
       "key":"key-1",
       "value":"200",
       "clock":1458748060
     },
     {
       "host":"hostName",
       "key":"key-4",
       "value":"test",
       "clock":1458748060}
     ]}
}

Wednesday, March 23, 2016

SQL Query- Where Value Between Two Columns

Imagine a simplified sample table that contains id, low_range, high_range. Low_range and High_range can be decimal ip address, zip codes or even timestamps.

id low_range high_range
1 400002 400120
5 407049 407340
5003 637190 637805
702984 849380 849875

We need to find row where a number is greater than low_range and lesser than high_range. Assumption is that maximum of one record and minimum of zero will be returned. 

SELECT id FROM table WHERE num > low_range AND num < high_range. 

The sql above might work well when we have probably few hundreds rows. But it is extremely slow with just few thousands records. Adding index on min_range (or / and max_range) will be helpful only for last few (or first few) records in index. For rest of rows, engine will consider a full table scan to be faster compared to using index. 

Solution 1:
SELECT id
FROM tab tab,
( SELECT max(low_range) as max_low_range
           FROM tab WHERE low_range <= num ) low_range_table
WHERE table.low_range = low_range_table.max_low_range
AND full_table.high_range >= num;
While above query might look complex to human, it makes life easier for database engine.   It first finds max low range available lesser than number. We have index on low_range; so this sub query will be fast. Next it joins with full table using this low_range. (Ideally, we should join with primary key). This will give exactly one row. Finally it validates if high range is still higher than number / string.

Explain plan:



Solution 2: 

          SELECT id
          FROM (
                    SELECT * FROM tab tab
                    WHERE low_range <= num
                     ORDER BY low_range DESC LIMIT 1) as max_low_range
          WHERE max_low_range.high_range >= num

Explain Plan



Thursday, December 10, 2015

Payment wallets in India - A to Z



Indian market is currently flooded with mobile wallet. Experts estimate mobile wallet market size of up to 19 billion USD by 2019. And everybody wants to get their bite. From telecoms to existing banks to business biggies to super charged startups, every body is launching mobile wallet. 

It is nightmare for businesses to integrate with these many wallets. With such high number of wallets, we will need another aggregrator that helps business to keep their life easy. How many mobile wallets does your business support? 

Following is list of semi open / semi closed wallets in India. (That I could mine out. I am sure I have missed plenty of them.)
  1. Airtel Money
  2. Axis Bank Lime
  3. Beam
  4. Chillr
  5. Citi Masterpass
  6. Citrus Pay
  7. Eko
  8. Etran Wallet
  9. Freecharge
  10. Hotremit
  11. ICash
  12. ItzCash
  13. Jio Money
  14. Mobikwik
  15. Mobomoney
  16. Momoe
  17. mPurse
  18. Nova Pay
  19. Obopay
  20. Ola Money
  21. Ongo
  22. Oxigen
  23. PayU
  24. Paytm
  25. Payzapp (HDFC)
  26. Pocket (ICICI)
  27. QuikWallet
  28. Smart Paisa
  29. Speed Pay
  30. Spice Mudra
  31. State Bank Buddy
  32. Tata mRupee
  33. Vodafone M-pesa
  34. X-Pay wallet
  35. YPayCash
  36. ZipCash

Wednesday, July 17, 2013

Google Form: Dynamically creating drop down list from a named range in Google Spreadsheet


I love using Google Form for collecting data and surveys. At times, I wish a feature, where inputs for Drop Down List, Checkbox or Multiple choice could be feed from excel sheet. This will help us when form itself is dependent on values from some other source.


We can achieve it with a simple google script. The script is executed from spreadsheet. It updates the Google form with a trigger set 'on change' on spreadsheet.

In below script, I take an existing google form and modify one of the drop down item in it. The values for this drop down item is fed from a named range in current active sheet.



Thursday, June 20, 2013

Obscuring data in database

At times, we may share database for development purpose. And we may need to obscure certain data. One example may be to obscure all email address in a particular table. Following sql statement obscures the local part of email address (before @ sign) and prefixes the domain name with two underscores (__).

update  Employeee_Table emp
set emp.email_id = concat(Translate(SUBSTR(emp.email_id, 1,  Instr(emp.email_id, '@')-1), 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', '84cBF75ZKnbEHofTQRSs6etN9zrW03yUmIkvxVijwJOdl1uAhMqCD2pGLXgaPY'), replace((SUBSTR(emp.email_id, Instr(emp.email_id, '@'))),'@','@__'))


Translate function, available in both - IBM DB2 and Oracle, changes character by character. So, in above query all 'A's will be changed '8', 'B's to 4, 'C's to 'c', 'D's to 'B' and so on. Replace function replaces '@' with '@__'

You can randomize string for your use at http://textmechanic.com/String-Randomizer.html

Obscuring domain name would have made key more predictable. So, either we should choose to use different keys for local part and domain name or just obscure local part.

Prefixing '_' with domain name helps in avoiding any accidental email to be sent to correct domain name.

Also, this isn't any encryption and should not be used where security is important. This is just to obscure data.