phpPgAdmin - Login disallowed

by GarciaPL on Saturday 21 December 2013

Few days ago I had pleasure to install on my web server called XAMPP delivered by Apache Friends one of the management tool for PostgreSQL called PhpPgAdmin. I must to say that installation is very easy, all you have to do is to put extracted files of this tool to htdocs folder, edit config located on phpPgAdmin/conf/config.inc.php and just run index.php through your web browser.

Unfortunately in my case there was some issue with connecting to PostgreSQL database. I had message something like "Login disallowed". I spent a lot of time to figure out the right solution, which I am going to share with you.

Just go to file on this path - phpPgAdmin/conf/config.inc.php and just change

$conf['extra_login_security'] = true


on


$conf['extra_login_security'] = false



Reference : [1] PhpPgAdmin Home Page [2] XAMPP Home Page

jQuery 1.6+ Change attr to prop

by GarciaPL on Saturday 7 December 2013

In the last days I was working on project which used one of the most powerful Javascript library jQuery in version 1.4.4. Yes, I know this version of jQuery is quite outdated. So, we decided to change it into jQuery 1.6.1. We expected some problems with change of library version, but what we discovered during looking for application errors was the change of handling of attributes and DOM object properties. I mean change function .attr to .prop

Before when we used jQuery 1.4.4 it was :


        jQuery 1.4 attr
        
        
    
    
        
        
    

Starting from jQuery 1.6+ it is :

        jQuery 1.6 prop
        
        
    
    
        
        
    



Reference : [1] Bugs.jquery.com Ticket 9088 [2] Ejohn.org - jQuery 1.6 and attr

Python PyXML gcc problem

by GarciaPL on Sunday 10 November 2013

I would like to give you some advice how to solve the problem which brought you here. So, I had a problem with installing on Ubuntu 12.04.3 LTS one of Python module called PyXML which can be used for XML Processing. I would like to give below a very very long description of error which I was faced with during the installation of PyXML.


python2.5 setup.py build
running build
running build_py
running build_ext
building '_xmlplus.parsers.pyexpat' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall 
-Wstrict-prototypes -fPIC -DXML_NS=1 -DXML_DTD=1 -DBYTEORDER=1234 
-DXML_CONTEXT_BYTES=1024 -DHAVE_MEMMOVE=1 -Iextensions/expat/lib 
-I/usr/include/python2.5 -c extensions/pyexpat.c -o 
build/temp.linux-i686-2.5/extensions/pyexpat.o
extensions/pyexpat.c:5:20: error: Python.h: No such file or directory
extensions/pyexpat.c:8:21: error: compile.h: No such file or directory
extensions/pyexpat.c:9:25: error: frameobject.h: No such file or directory
extensions/pyexpat.c:63: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or 
‘__attribute__’ before ‘*’ token
extensions/pyexpat.c:70: error: expected specifier-qualifier-list before 
‘PyObject_HEAD’
extensions/pyexpat.c:89: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or 
‘__attribute__’ before ‘Xmlparsetype’
extensions/pyexpat.c:98: error: expected specifier-qualifier-list before 
‘PyCodeObject’
extensions/pyexpat.c:108: error: expected ‘)’ before ‘*’ token
extensions/pyexpat.c:123: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or 
‘__attribute__’ before ‘*’ token
extensions/pyexpat.c: In function ‘have_handler’:
extensions/pyexpat.c:150: error: ‘PyObject’ undeclared (first use in 
this function)
extensions/pyexpat.c:150: error: (Each undeclared identifier is reported 
only once
extensions/pyexpat.c:150: error: for each function it appears in.)
extensions/pyexpat.c:150: error: ‘handler’ undeclared (first use in this 
function)
extensions/pyexpat.c:150: error: ‘xmlparseobject’ has no member named 
‘handlers’
extensions/pyexpat.c: At top level:
extensions/pyexpat.c:154: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or 
‘__attribute__’ before ‘*’ token
extensions/pyexpat.c:201: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or 
‘__attribute__’ before ‘*’ token
extensions/pyexpat.c:214: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or 
‘__attribute__’ before ‘*’ token
extensions/pyexpat.c: In function ‘flag_error’:
extensions/pyexpat.c:248: error: ‘xmlparseobject’ has no member named 
‘itself’
extensions/pyexpat.c: At top level:
extensions/pyexpat.c:252: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or 
‘__attribute__’ before ‘*’ token
extensions/pyexpat.c:305: error: expected ‘)’ before ‘*’ token
extensions/pyexpat.c:332: error: expected ‘)’ before ‘*’ token
extensions/pyexpat.c:367: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or 
‘__attribute__’ before ‘*’ token
extensions/pyexpat.c:419: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or 
‘__attribute__’ before ‘*’ token
extensions/pyexpat.c: In function ‘call_character_handler’:
extensions/pyexpat.c:444: error: ‘PyObject’ undeclared (first use in 
this function)
extensions/pyexpat.c:444: error: ‘args’ undeclared (first use in this 
function)
extensions/pyexpat.c:445: error: ‘temp’ undeclared (first use in this 
function)
extensions/pyexpat.c:447: warning: implicit declaration of function 
‘PyTuple_New’
extensions/pyexpat.c:455: warning: implicit declaration of function 
‘conv_string_len_to_utf8’
extensions/pyexpat.c:458: warning: implicit declaration of function 
‘Py_DECREF’
extensions/pyexpat.c:462: warning: implicit declaration of function 
‘PyTuple_SET_ITEM’
extensions/pyexpat.c:464: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c:465: warning: implicit declaration of function 
‘call_with_frame’
extensions/pyexpat.c:465: warning: implicit declaration of function 
‘getcode’
extensions/pyexpat.c:466: error: ‘xmlparseobject’ has no member named 
‘handlers’
extensions/pyexpat.c:468: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c: In function ‘flush_character_buffer’:
extensions/pyexpat.c:482: error: ‘xmlparseobject’ has no member named 
‘buffer’
extensions/pyexpat.c:482: error: ‘xmlparseobject’ has no member named 
‘buffer_used’
extensions/pyexpat.c:484: error: ‘xmlparseobject’ has no member named 
‘buffer’
extensions/pyexpat.c:484: error: ‘xmlparseobject’ has no member named 
‘buffer_used’
extensions/pyexpat.c:485: error: ‘xmlparseobject’ has no member named 
‘buffer_used’
extensions/pyexpat.c: In function ‘my_CharacterDataHandler’:
extensions/pyexpat.c:493: error: ‘xmlparseobject’ has no member named 
‘buffer’
extensions/pyexpat.c:496: error: ‘xmlparseobject’ has no member named 
‘buffer_used’
extensions/pyexpat.c:496: error: ‘xmlparseobject’ has no member named 
‘buffer_size’
extensions/pyexpat.c:505: error: ‘xmlparseobject’ has no member named 
‘buffer_size’
extensions/pyexpat.c:507: error: ‘xmlparseobject’ has no member named 
‘buffer_used’
extensions/pyexpat.c:510: warning: implicit declaration of function ‘memcpy’
extensions/pyexpat.c:510: warning: incompatible implicit declaration of 
built-in function ‘memcpy’
extensions/pyexpat.c:510: error: ‘xmlparseobject’ has no member named 
‘buffer’
extensions/pyexpat.c:510: error: ‘xmlparseobject’ has no member named 
‘buffer_used’
extensions/pyexpat.c:512: error: ‘xmlparseobject’ has no member named 
‘buffer_used’
extensions/pyexpat.c: In function ‘my_StartElementHandler’:
extensions/pyexpat.c:524: error: ‘PyObject’ undeclared (first use in 
this function)
extensions/pyexpat.c:524: error: ‘container’ undeclared (first use in 
this function)
extensions/pyexpat.c:524: error: ‘rv’ undeclared (first use in this 
function)
extensions/pyexpat.c:524: warning: left-hand operand of comma expression 
has no effect
extensions/pyexpat.c:524: error: ‘args’ undeclared (first use in this 
function)
extensions/pyexpat.c:524: warning: left-hand operand of comma expression 
has no effect
extensions/pyexpat.c:532: error: ‘xmlparseobject’ has no member named 
‘specified_attributes’
extensions/pyexpat.c:533: error: ‘xmlparseobject’ has no member named 
‘itself’
extensions/pyexpat.c:541: error: ‘xmlparseobject’ has no member named 
‘ordered_attributes’
extensions/pyexpat.c:542: warning: implicit declaration of function 
‘PyList_New’
extensions/pyexpat.c:544: warning: implicit declaration of function 
‘PyDict_New’
extensions/pyexpat.c:550: error: ‘n’ undeclared (first use in this function)
extensions/pyexpat.c:550: warning: implicit declaration of function 
‘string_intern’
extensions/pyexpat.c:551: error: ‘v’ undeclared (first use in this function)
extensions/pyexpat.c:557: warning: implicit declaration of function 
‘conv_string_to_utf8’
extensions/pyexpat.c:564: error: ‘xmlparseobject’ has no member named 
‘ordered_attributes’
extensions/pyexpat.c:565: warning: implicit declaration of function 
‘PyList_SET_ITEM’
extensions/pyexpat.c:568: warning: implicit declaration of function 
‘PyDict_SetItem’
extensions/pyexpat.c:579: warning: implicit declaration of function 
‘Py_BuildValue’
extensions/pyexpat.c:585: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c:587: error: ‘xmlparseobject’ has no member named 
‘handlers’
extensions/pyexpat.c:588: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c: In function ‘my_EndElementHandler’:
extensions/pyexpat.c:636: error: ‘PyObject’ undeclared (first use in 
this function)
extensions/pyexpat.c:636: error: ‘args’ undeclared (first use in this 
function)
extensions/pyexpat.c:636: error: ‘rv’ undeclared (first use in this 
function)
extensions/pyexpat.c:636: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c:636: error: ‘xmlparseobject’ has no member named 
‘handlers’
extensions/pyexpat.c:636: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c: In function ‘my_ProcessingInstructionHandler’:
extensions/pyexpat.c:640: error: ‘PyObject’ undeclared (first use in 
this function)
extensions/pyexpat.c:640: error: ‘args’ undeclared (first use in this 
function)
extensions/pyexpat.c:640: error: ‘rv’ undeclared (first use in this 
function)
extensions/pyexpat.c:640: error: ‘conv_string_to_utf8’ undeclared (first 
use in this function)
extensions/pyexpat.c:640: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c:640: error: ‘xmlparseobject’ has no member named 
‘handlers’
extensions/pyexpat.c:640: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c: In function ‘my_UnparsedEntityDeclHandler’:
extensions/pyexpat.c:646: error: ‘PyObject’ undeclared (first use in 
this function)
extensions/pyexpat.c:646: error: ‘args’ undeclared (first use in this 
function)
extensions/pyexpat.c:646: error: ‘rv’ undeclared (first use in this 
function)
extensions/pyexpat.c:646: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c:646: error: ‘xmlparseobject’ has no member named 
‘handlers’
extensions/pyexpat.c:646: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c: In function ‘my_EntityDeclHandler’:
extensions/pyexpat.c:659: error: ‘PyObject’ undeclared (first use in 
this function)
extensions/pyexpat.c:659: error: ‘args’ undeclared (first use in this 
function)
extensions/pyexpat.c:659: error: ‘rv’ undeclared (first use in this 
function)
extensions/pyexpat.c:659: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c:659: error: ‘xmlparseobject’ has no member named 
‘handlers’
extensions/pyexpat.c:659: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c: In function ‘my_XmlDeclHandler’:
extensions/pyexpat.c:696: error: ‘PyObject’ undeclared (first use in 
this function)
extensions/pyexpat.c:696: error: ‘args’ undeclared (first use in this 
function)
extensions/pyexpat.c:696: error: ‘rv’ undeclared (first use in this 
function)
extensions/pyexpat.c:696: error: ‘conv_string_to_utf8’ undeclared (first 
use in this function)
extensions/pyexpat.c:696: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c:696: error: ‘xmlparseobject’ has no member named 
‘handlers’
extensions/pyexpat.c:696: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c: At top level:
extensions/pyexpat.c:705: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or 
‘__attribute__’ before ‘*’ token
extensions/pyexpat.c: In function ‘my_ElementDeclHandler’:
extensions/pyexpat.c:737: error: ‘PyObject’ undeclared (first use in 
this function)
extensions/pyexpat.c:737: error: ‘args’ undeclared (first use in this 
function)
extensions/pyexpat.c:740: error: ‘rv’ undeclared (first use in this 
function)
extensions/pyexpat.c:741: error: ‘modelobj’ undeclared (first use in 
this function)
extensions/pyexpat.c:741: error: ‘nameobj’ undeclared (first use in this 
function)
extensions/pyexpat.c:741: warning: left-hand operand of comma expression 
has no effect
extensions/pyexpat.c:751: warning: implicit declaration of function 
‘conv_content_model’
extensions/pyexpat.c:751: error: ‘conv_string_to_utf8’ undeclared (first 
use in this function)
extensions/pyexpat.c:769: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c:771: error: ‘xmlparseobject’ has no member named 
‘handlers’
extensions/pyexpat.c:772: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c:780: warning: implicit declaration of function 
‘Py_XDECREF’
extensions/pyexpat.c:781: error: ‘xmlparseobject’ has no member named 
‘itself’
extensions/pyexpat.c: In function ‘my_AttlistDeclHandler’:
extensions/pyexpat.c:785: error: ‘PyObject’ undeclared (first use in 
this function)
extensions/pyexpat.c:785: error: ‘args’ undeclared (first use in this 
function)
extensions/pyexpat.c:785: error: ‘rv’ undeclared (first use in this 
function)
extensions/pyexpat.c:785: error: ‘conv_string_to_utf8’ undeclared (first 
use in this function)
extensions/pyexpat.c:785: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c:785: error: ‘xmlparseobject’ has no member named 
‘handlers’
extensions/pyexpat.c:785: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c: In function ‘my_SkippedEntityHandler’:
extensions/pyexpat.c:798: error: ‘PyObject’ undeclared (first use in 
this function)
extensions/pyexpat.c:798: error: ‘args’ undeclared (first use in this 
function)
extensions/pyexpat.c:798: error: ‘rv’ undeclared (first use in this 
function)
extensions/pyexpat.c:798: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c:798: error: ‘xmlparseobject’ has no member named 
‘handlers’
extensions/pyexpat.c:798: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c: In function ‘my_NotationDeclHandler’:
extensions/pyexpat.c:806: error: ‘PyObject’ undeclared (first use in 
this function)
extensions/pyexpat.c:806: error: ‘args’ undeclared (first use in this 
function)
extensions/pyexpat.c:806: error: ‘rv’ undeclared (first use in this 
function)
extensions/pyexpat.c:806: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c:806: error: ‘xmlparseobject’ has no member named 
‘handlers’
extensions/pyexpat.c:806: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c: In function ‘my_StartNamespaceDeclHandler’:
extensions/pyexpat.c:816: error: ‘PyObject’ undeclared (first use in 
this function)
extensions/pyexpat.c:816: error: ‘args’ undeclared (first use in this 
function)
extensions/pyexpat.c:816: error: ‘rv’ undeclared (first use in this 
function)
extensions/pyexpat.c:816: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c:816: error: ‘xmlparseobject’ has no member named 
‘handlers’
extensions/pyexpat.c:816: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c: In function ‘my_EndNamespaceDeclHandler’:
extensions/pyexpat.c:823: error: ‘PyObject’ undeclared (first use in 
this function)
extensions/pyexpat.c:823: error: ‘args’ undeclared (first use in this 
function)
extensions/pyexpat.c:823: error: ‘rv’ undeclared (first use in this 
function)
extensions/pyexpat.c:823: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c:823: error: ‘xmlparseobject’ has no member named 
‘handlers’
extensions/pyexpat.c:823: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c: In function ‘my_CommentHandler’:
extensions/pyexpat.c:828: error: ‘PyObject’ undeclared (first use in 
this function)
extensions/pyexpat.c:828: error: ‘args’ undeclared (first use in this 
function)
extensions/pyexpat.c:828: error: ‘rv’ undeclared (first use in this 
function)
extensions/pyexpat.c:828: error: ‘conv_string_to_utf8’ undeclared (first 
use in this function)
extensions/pyexpat.c:828: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c:828: error: ‘xmlparseobject’ has no member named 
‘handlers’
extensions/pyexpat.c:828: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c: In function ‘my_StartCdataSectionHandler’:
extensions/pyexpat.c:832: error: ‘PyObject’ undeclared (first use in 
this function)
extensions/pyexpat.c:832: error: ‘args’ undeclared (first use in this 
function)
extensions/pyexpat.c:832: error: ‘rv’ undeclared (first use in this 
function)
extensions/pyexpat.c:832: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c:832: error: ‘xmlparseobject’ has no member named 
‘handlers’
extensions/pyexpat.c:832: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c: In function ‘my_EndCdataSectionHandler’:
extensions/pyexpat.c:836: error: ‘PyObject’ undeclared (first use in 
this function)
extensions/pyexpat.c:836: error: ‘args’ undeclared (first use in this 
function)
extensions/pyexpat.c:836: error: ‘rv’ undeclared (first use in this 
function)
extensions/pyexpat.c:836: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c:836: error: ‘xmlparseobject’ has no member named 
‘handlers’
extensions/pyexpat.c:836: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c: In function ‘my_DefaultHandler’:
extensions/pyexpat.c:841: error: ‘PyObject’ undeclared (first use in 
this function)
extensions/pyexpat.c:841: error: ‘args’ undeclared (first use in this 
function)
extensions/pyexpat.c:841: error: ‘rv’ undeclared (first use in this 
function)
extensions/pyexpat.c:841: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c:841: error: ‘xmlparseobject’ has no member named 
‘handlers’
extensions/pyexpat.c:841: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c: In function ‘my_DefaultHandlerExpandHandler’:
extensions/pyexpat.c:845: error: ‘PyObject’ undeclared (first use in 
this function)
extensions/pyexpat.c:845: error: ‘args’ undeclared (first use in this 
function)
extensions/pyexpat.c:845: error: ‘rv’ undeclared (first use in this 
function)
extensions/pyexpat.c:845: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c:845: error: ‘xmlparseobject’ has no member named 
‘handlers’
extensions/pyexpat.c:845: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c: In function ‘my_NotStandaloneHandler’:
extensions/pyexpat.c:862: error: ‘PyObject’ undeclared (first use in 
this function)
extensions/pyexpat.c:862: error: ‘args’ undeclared (first use in this 
function)
extensions/pyexpat.c:862: error: ‘rv’ undeclared (first use in this 
function)
extensions/pyexpat.c:862: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c:862: error: ‘xmlparseobject’ has no member named 
‘handlers’
extensions/pyexpat.c:862: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c:862: warning: implicit declaration of function 
‘PyInt_AsLong’
extensions/pyexpat.c: In function ‘my_ExternalEntityRefHandler’:
extensions/pyexpat.c:866: error: ‘PyObject’ undeclared (first use in 
this function)
extensions/pyexpat.c:866: error: ‘args’ undeclared (first use in this 
function)
extensions/pyexpat.c:866: error: ‘rv’ undeclared (first use in this 
function)
extensions/pyexpat.c:866: error: ‘conv_string_to_utf8’ undeclared (first 
use in this function)
extensions/pyexpat.c:866: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c:866: error: ‘xmlparseobject’ has no member named 
‘handlers’
extensions/pyexpat.c:866: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c: In function ‘my_StartDoctypeDeclHandler’:
extensions/pyexpat.c:881: error: ‘PyObject’ undeclared (first use in 
this function)
extensions/pyexpat.c:881: error: ‘args’ undeclared (first use in this 
function)
extensions/pyexpat.c:881: error: ‘rv’ undeclared (first use in this 
function)
extensions/pyexpat.c:881: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c:881: error: ‘xmlparseobject’ has no member named 
‘handlers’
extensions/pyexpat.c:881: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c: In function ‘my_EndDoctypeDeclHandler’:
extensions/pyexpat.c:889: error: ‘PyObject’ undeclared (first use in 
this function)
extensions/pyexpat.c:889: error: ‘args’ undeclared (first use in this 
function)
extensions/pyexpat.c:889: error: ‘rv’ undeclared (first use in this 
function)
extensions/pyexpat.c:889: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c:889: error: ‘xmlparseobject’ has no member named 
‘handlers’
extensions/pyexpat.c:889: error: ‘xmlparseobject’ has no member named 
‘in_callback’
extensions/pyexpat.c: At top level:
extensions/pyexpat.c:893: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or 
‘__attribute__’ before ‘*’ token
extensions/pyexpat.c:912: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or 
‘__attribute__’ before ‘*’ token
extensions/pyexpat.c:930: error: expected declaration specifiers or 
‘...’ before ‘PyObject’
extensions/pyexpat.c: In function ‘readinst’:
extensions/pyexpat.c:932: error: ‘PyObject’ undeclared (first use in 
this function)
extensions/pyexpat.c:932: error: ‘arg’ undeclared (first use in this 
function)
extensions/pyexpat.c:933: error: ‘bytes’ undeclared (first use in this 
function)
extensions/pyexpat.c:934: error: ‘str’ undeclared (first use in this 
function)
extensions/pyexpat.c:937: warning: implicit declaration of function 
‘PyInt_FromLong’
extensions/pyexpat.c:948: warning: implicit declaration of function 
‘PyObject_CallObject’
extensions/pyexpat.c:948: error: ‘meth’ undeclared (first use in this 
function)
extensions/pyexpat.c:956: warning: implicit declaration of function 
‘PyString_Check’
extensions/pyexpat.c:957: warning: implicit declaration of function 
‘PyErr_Format’
extensions/pyexpat.c:957: error: ‘PyExc_TypeError’ undeclared (first use 
in this function)
extensions/pyexpat.c:962: warning: implicit declaration of function 
‘PyString_GET_SIZE’
extensions/pyexpat.c:964: error: ‘PyExc_ValueError’ undeclared (first 
use in this function)
extensions/pyexpat.c:970: warning: incompatible implicit declaration of 
built-in function ‘memcpy’
extensions/pyexpat.c:970: warning: implicit declaration of function 
‘PyString_AsString’
extensions/pyexpat.c:970: warning: passing argument 2 of ‘memcpy’ makes 
pointer from integer without a cast
extensions/pyexpat.c:970: note: expected ‘const void *’ but argument is 
of type ‘int’
extensions/pyexpat.c: At top level:
extensions/pyexpat.c:981: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or 
‘__attribute__’ before ‘*’ token
extensions/pyexpat.c:1044: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or 
‘__attribute__’ before ‘*’ token
extensions/pyexpat.c:1062: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or 
‘__attribute__’ before ‘*’ token
extensions/pyexpat.c:1077: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or 
‘__attribute__’ before ‘*’ token
extensions/pyexpat.c:1108: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or 
‘__attribute__’ before ‘*’ token
extensions/pyexpat.c:1203: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or 
‘__attribute__’ before ‘*’ token
extensions/pyexpat.c:1223: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or 
‘__attribute__’ before ‘*’ token
extensions/pyexpat.c:1242: error: array type has incomplete element type
extensions/pyexpat.c:1243: error: ‘PyCFunction’ undeclared here (not in 
a function)
extensions/pyexpat.c:1243: error: expected ‘}’ before ‘xmlparse_Parse’
extensions/pyexpat.c:1245: error: expected ‘}’ before ‘xmlparse_ParseFile’
extensions/pyexpat.c:1247: error: expected ‘}’ before ‘xmlparse_SetBase’
extensions/pyexpat.c:1249: error: expected ‘}’ before ‘xmlparse_GetBase’
extensions/pyexpat.c:1251: error: expected ‘}’ before 
‘xmlparse_ExternalEntityParserCreate’
extensions/pyexpat.c:1253: error: expected ‘}’ before 
‘xmlparse_SetParamEntityParsing’
extensions/pyexpat.c:1255: error: expected ‘}’ before 
‘xmlparse_GetInputContext’
extensions/pyexpat.c:1258: error: expected ‘}’ before 
‘xmlparse_UseForeignDTD’
extensions/pyexpat.c:1320: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or 
‘__attribute__’ before ‘*’ token
extensions/pyexpat.c: In function ‘xmlparse_dealloc’:
extensions/pyexpat.c:1395: warning: implicit declaration of function 
‘PyObject_GC_Fini’
extensions/pyexpat.c:1397: error: ‘xmlparseobject’ has no member named 
‘itself’
extensions/pyexpat.c:1398: error: ‘xmlparseobject’ has no member named 
‘itself’
extensions/pyexpat.c:1399: error: ‘xmlparseobject’ has no member named 
‘itself’
extensions/pyexpat.c:1401: error: ‘xmlparseobject’ has no member named 
‘handlers’
extensions/pyexpat.c:1402: error: ‘PyObject’ undeclared (first use in 
this function)
extensions/pyexpat.c:1402: error: ‘temp’ undeclared (first use in this 
function)
extensions/pyexpat.c:1404: error: ‘xmlparseobject’ has no member named 
‘handlers’
extensions/pyexpat.c:1405: error: ‘xmlparseobject’ has no member named 
‘handlers’
extensions/pyexpat.c:1408: error: ‘xmlparseobject’ has no member named 
‘handlers’
extensions/pyexpat.c:1409: error: ‘xmlparseobject’ has no member named 
‘handlers’
extensions/pyexpat.c:1411: error: ‘xmlparseobject’ has no member named 
‘buffer’
extensions/pyexpat.c:1412: error: ‘xmlparseobject’ has no member named 
‘buffer’
extensions/pyexpat.c:1413: error: ‘xmlparseobject’ has no member named 
‘buffer’
extensions/pyexpat.c:1415: error: ‘xmlparseobject’ has no member named 
‘intern’
extensions/pyexpat.c:1418: warning: implicit declaration of function 
‘PyObject_Del’
extensions/pyexpat.c: In function ‘handlername2int’:
extensions/pyexpat.c:1430: warning: implicit declaration of function 
‘strcmp’
extensions/pyexpat.c: At top level:
extensions/pyexpat.c:1437: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or 
‘__attribute__’ before ‘*’ token
extensions/pyexpat.c:1445: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or 
‘__attribute__’ before ‘*’ token
extensions/pyexpat.c:1549: error: expected declaration specifiers or 
‘...’ before ‘PyObject’
extensions/pyexpat.c: In function ‘sethandler’:
extensions/pyexpat.c:1554: error: ‘PyObject’ undeclared (first use in 
this function)
extensions/pyexpat.c:1554: error: ‘temp’ undeclared (first use in this 
function)
extensions/pyexpat.c:1554: error: ‘xmlparseobject’ has no member named 
‘handlers’
extensions/pyexpat.c:1556: error: ‘v’ undeclared (first use in this 
function)
extensions/pyexpat.c:1556: error: ‘Py_None’ undeclared (first use in 
this function)
extensions/pyexpat.c:1559: warning: implicit declaration of function 
‘Py_INCREF’
extensions/pyexpat.c:1562: error: ‘xmlparseobject’ has no member named 
‘handlers’
extensions/pyexpat.c:1564: error: ‘xmlparseobject’ has no member named 
‘itself’
extensions/pyexpat.c: At top level:
extensions/pyexpat.c:1571: error: expected declaration specifiers or 
‘...’ before ‘PyObject’
extensions/pyexpat.c: In function ‘xmlparse_setattr’:
extensions/pyexpat.c:1574: error: ‘v’ undeclared (first use in this 
function)
extensions/pyexpat.c:1575: warning: implicit declaration of function 
‘PyErr_SetString’
extensions/pyexpat.c:1575: error: ‘PyExc_RuntimeError’ undeclared (first 
use in this function)
extensions/pyexpat.c:1579: warning: implicit declaration of function 
‘PyObject_IsTrue’
extensions/pyexpat.c:1580: error: ‘xmlparseobject’ has no member named 
‘buffer’
extensions/pyexpat.c:1581: error: ‘xmlparseobject’ has no member named 
‘buffer’
extensions/pyexpat.c:1581: error: ‘xmlparseobject’ has no member named 
‘buffer_size’
extensions/pyexpat.c:1582: error: ‘xmlparseobject’ has no member named 
‘buffer’
extensions/pyexpat.c:1583: warning: implicit declaration of function 
‘PyErr_NoMemory’
extensions/pyexpat.c:1586: error: ‘xmlparseobject’ has no member named 
‘buffer_used’
extensions/pyexpat.c:1589: error: ‘xmlparseobject’ has no member named 
‘buffer’
extensions/pyexpat.c:1592: error: ‘xmlparseobject’ has no member named 
‘buffer’
extensions/pyexpat.c:1593: error: ‘xmlparseobject’ has no member named 
‘buffer’
extensions/pyexpat.c:1599: error: ‘xmlparseobject’ has no member named 
‘ns_prefixes’
extensions/pyexpat.c:1601: error: ‘xmlparseobject’ has no member named 
‘ns_prefixes’
extensions/pyexpat.c:1602: error: ‘xmlparseobject’ has no member named 
‘itself’
extensions/pyexpat.c:1602: error: ‘xmlparseobject’ has no member named 
‘ns_prefixes’
extensions/pyexpat.c:1607: error: ‘xmlparseobject’ has no member named 
‘ordered_attributes’
extensions/pyexpat.c:1609: error: ‘xmlparseobject’ has no member named 
‘ordered_attributes’
extensions/pyexpat.c:1615: error: ‘PyExc_ValueError’ undeclared (first 
use in this function)
extensions/pyexpat.c:1623: error: ‘xmlparseobject’ has no member named 
‘returns_unicode’
extensions/pyexpat.c:1628: error: ‘xmlparseobject’ has no member named 
‘specified_attributes’
extensions/pyexpat.c:1630: error: ‘xmlparseobject’ has no member named 
‘specified_attributes’
extensions/pyexpat.c:1642: error: too many arguments to function 
‘sethandler’
extensions/pyexpat.c:1645: error: ‘PyExc_AttributeError’ undeclared 
(first use in this function)
extensions/pyexpat.c: At top level:
extensions/pyexpat.c:1676: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or 
‘__attribute__’ before ‘Xmlparsetype’
extensions/pyexpat.c:1719: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or 
‘__attribute__’ before ‘*’ token
extensions/pyexpat.c:1766: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or 
‘__attribute__’ before ‘*’ token
extensions/pyexpat.c:1778: error: array type has incomplete element type
extensions/pyexpat.c:1779: error: expected ‘}’ before ‘pyexpat_ParserCreate’
extensions/pyexpat.c:1781: error: expected ‘}’ before ‘pyexpat_ErrorString’
extensions/pyexpat.c:1797: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or 
‘__attribute__’ before ‘*’ token
extensions/pyexpat.c: In function ‘initpyexpat’:
extensions/pyexpat.c:1835: error: ‘PyObject’ undeclared (first use in 
this function)
extensions/pyexpat.c:1835: error: ‘m’ undeclared (first use in this 
function)
extensions/pyexpat.c:1835: error: ‘d’ undeclared (first use in this 
function)
extensions/pyexpat.c:1835: warning: left-hand operand of comma 
expression has no effect
extensions/pyexpat.c:1836: error: ‘errmod_name’ undeclared (first use in 
this function)
extensions/pyexpat.c:1836: warning: implicit declaration of function 
‘PyString_FromString’
extensions/pyexpat.c:1837: error: ‘errors_module’ undeclared (first use 
in this function)
extensions/pyexpat.c:1838: error: ‘modelmod_name’ undeclared (first use 
in this function)
extensions/pyexpat.c:1839: error: ‘model_module’ undeclared (first use 
in this function)
extensions/pyexpat.c:1840: error: ‘sys_modules’ undeclared (first use in 
this function)
extensions/pyexpat.c:1848: error: ‘Xmlparsetype’ undeclared (first use 
in this function)
extensions/pyexpat.c:1848: error: ‘PyType_Type’ undeclared (first use in 
this function)
extensions/pyexpat.c:1851: warning: implicit declaration of function 
‘Py_InitModule3’
extensions/pyexpat.c:1855: error: ‘ErrorObject’ undeclared (first use in 
this function)
extensions/pyexpat.c:1856: warning: implicit declaration of function 
‘PyErr_NewException’
extensions/pyexpat.c:1862: warning: implicit declaration of function 
‘PyModule_AddObject’
extensions/pyexpat.c:1866: error: expected expression before ‘)’ token
extensions/pyexpat.c:1868: warning: implicit declaration of function 
‘get_version_string’
extensions/pyexpat.c:1869: warning: implicit declaration of function 
‘PyModule_AddStringConstant’
extensions/pyexpat.c:1889: warning: implicit declaration of function 
‘PySys_GetObject’
extensions/pyexpat.c:1890: warning: implicit declaration of function 
‘PyModule_GetDict’
extensions/pyexpat.c:1891: warning: implicit declaration of function 
‘PyDict_GetItem’
extensions/pyexpat.c:1893: warning: implicit declaration of function 
‘PyModule_New’
extensions/pyexpat.c:1918: error: ‘list’ undeclared (first use in this 
function)
extensions/pyexpat.c:1921: warning: implicit declaration of function 
‘PyErr_Clear’
extensions/pyexpat.c:1926: error: ‘item’ undeclared (first use in this 
function)
extensions/pyexpat.c:1933: warning: implicit declaration of function 
‘PyList_Append’
extensions/pyexpat.c:1996: warning: implicit declaration of function 
‘PyModule_AddIntConstant’
extensions/pyexpat.c: In function ‘clear_handlers’:
extensions/pyexpat.c:2023: error: ‘PyObject’ undeclared (first use in 
this function)
extensions/pyexpat.c:2023: error: ‘temp’ undeclared (first use in this 
function)
extensions/pyexpat.c:2027: error: ‘xmlparseobject’ has no member named 
‘handlers’
extensions/pyexpat.c:2029: error: ‘xmlparseobject’ has no member named 
‘handlers’
extensions/pyexpat.c:2030: error: ‘xmlparseobject’ has no member named 
‘handlers’
extensions/pyexpat.c:2032: error: ‘xmlparseobject’ has no member named 
‘itself’
error: command 'gcc' failed with exit status 1


Quite enormous, isn't it ? :) So, fix of this problem is very easy - just install python-dev package in Ubuntu. You can use this command in your terminal :

sudo apt-get install python-dev


Reference : [1] Gmane.org XML Processing [2] PyXML Home Page Project

Spring Data Access Object (DAO)

by GarciaPL on Saturday 26 October 2013

I would like to present a small example of using Data Access Object (DAO) in Spring. This is a kind of component which provides unified interface to communication between application and source of data for instance database or file. Application using DAO does not have to know the way the data is stored or manipulated in database. This component is commonly used in MVC (Model-View-Controller) which allows to separate data access model from business logic and presentation layer. In this example datasource is NoSQL Database MongoDB.

Below I put some example of DAO Entity called SettingsDao and its Implementation called SettingsDaoImpl.

Entity SettingsDAO :

package pl.eventoo.mongodb.dao;

import pl.eventoo.domain.Settings;

/**
 * Interface of credentials settings
 *
 * @author lukasz
 */
public interface SettingsDao {

    /**
     * Interface for save credentials
     *
     * @param settings 
     */
    public void saveSettings(Settings settings);
    
    /**
     * Interface for update credentials
     * 
     * @param settings
     * @return
     */
    public boolean updateSettings(Settings settings);

    /**
     * Interface for read credentials
     *
     * @return
     */
    public Settings readSettings();
}



Implementation of Entity DAO SettingsDaoImpl :

package pl.eventoo.mongodb.dao;

import com.google.code.morphia.DAO;
import com.google.code.morphia.query.UpdateOperations;
import com.google.code.morphia.query.UpdateResults;
import pl.eventoo.domain.Settings;
import pl.eventoo.mongodb.factory.MongoConnectionManager;

/**
 * Implementation Dao for credentials settings
 *
 * @author lukasz
 */
public class SettingsDaoImpl extends DAO Settings, String implements SettingsDao {

    public SettingsDaoImpl() {
        super(Settings.class, MongoConnectionManager.instance().getDb());
    }

    @Override
    public void saveSettings(Settings settings) {
        save(settings);
    }

    @Override
    public Settings readSettings() {
        return ds.find(Settings.class).get();
    }

    @Override
    public boolean updateSettings(Settings settings) {
        UpdateOperations createUpdateOperations = ds.createUpdateOperations(Settings.class).set("interval_cron", settings.getInterval_cron()).set("time_difference_event", settings.getTime_difference_event());
        UpdateResults update = ds.update(ds.createQuery(Settings.class), createUpdateOperations);
        return update.getHadError();
    }
}


Reference : [1] Springbyexample.org Person DAO [2] Spring Framework 3.0 Docs DAO [3] Spring Framework 3.2 Docs MVC
[4] Pastebin Settings DAO Source
[5] Pastebin Settings Implementation DAO Source

SQL Joins Explain Diagram

by GarciaPL on Friday 25 October 2013

I must say that this one diagram of SQL Joins is one of the most memorizing image about how joins in sql works. Enjoy :)

SQL Joins
SQL Joins Explain

Reference :
[1] Codeproject.com Visual Representation of SQL Joins

MySQL Refresh processlist every second

by GarciaPL on Wednesday 9 October 2013

Very useful piece of command line query which will help you to keep an eye on execution time of queries which are performed in your MySQL database. It helps me when I ask myself : 'Hm ... I am wondering if this query is now executed ... '. This question can be sometime annoying, so this is quite helpful adoption of mysqladmin tool.

mysqladmin -u root -p -i 1 processlist

-u your username
-p you be pleased to give database password
-i 1 interval which equals 1 second


Example output :

+----+------+-----------+----+---------+------+-------+------------------+
| Id | User | Host      | db | Command | Time | State | Info             |
+----+------+-----------+----+---------+------+-------+------------------+
| 43 | root | localhost |    | Query   | 0    |       | show processlist |
+----+------+-----------+----+---------+------+-------+------------------+

Reference : [1] Mysqladmin Tool Doc

Add User in Nagios

by GarciaPL on Thursday 22 August 2013

I just wrote a small script (written in Perl) which performs adding user to merlin database without doing it manually via web interface. In my server environment script works, but I can not guarantee you that it will work in yours environments ;)

Configuration of script :
- htpasswd_directory - directory of htpasswd file for example /opt/nagios/etc/
- htpasswd_file - name of htpasswd file used by Nagios for example htpasswd.users
- nagios_cgi_directory - main Nagios directory for example /opt/nagios/etc/
- nagios_cgi_cfg_file - name of main Nagios configuration file which stores users information for example cgi.cfg
- nagios_cgi_fields - name of user privileges to be added in cgi file for example authorized_for_all_services and authorized_for_all_hosts
- domain - if your company uses a domain name in users accounts for example @MICROSOFT.COM
- comma - it is obvious ;)
- password_algorithm (relative)
- password_user_merlin (relative)


This script is some kind of guide to develop your own script to adding faster users in nagios infrastructure ;)

#!/usr/bin/perl -w
######################################
# Info : Add User Nagios on st1monms2
# Version : 1.0
# Date : 7 luty 2012
# Author : Lukasz Ciesluk
# Help : http://pl.linkedin.com/in/lukaszciesluk/
######################################
#
# Run :
# chmod +x AddUserNagios_st1monms2.pl
# ./AddUserNagios_st1monms2.pl -h (for help)
# ./AddUserNagios_st1monms2.pl -u  --username_db  --password_db  --database 

use strict;
use warnings;
use Getopt::Long;
use DBI;
use Tie::File;

my $new_nagios_user = undef;
my $username_db = undef;
my $password_db = undef;
my $database = undef;
my $sql = undef;
my $dbh = undef;
my $help = undef;

my $htpasswd_directory = "/opt/nagios/etc/";
my $htpasswd_file = "htpasswd.users";
my $nagios_cgi_directory = "/opt/nagios/etc/";
my $nagios_cgi_cfg_file = "cgi.cfg";
my @nagios_cgi_fields = ( 'authorized_for_all_services', 'authorized_for_all_hosts', 'authorized_for_read_only' );

my $domain = "\@BANK.COM.PL";
my $comma = ",";
my $password_algorithm = "b64_sha1";
my $password_user_merlin = "4insgmC8hl++J1uTcPVCtfo2uX0=";

sub usage {
    print "$0 --u  --dbu  --dbp  --dbd \n";
}

sub connect_db_merlin {
 $dbh = DBI->connect("dbi:mysql:database=$database;"."host=localhost;port=3306", $username_db, $password_db) || die "Nie mozna sie polaczyc do bazy: $DBI::errstr";
}

sub duplicate_htpasswd {
 my ($nagios_user_create) = @_;
 if (-d $htpasswd_directory) {
  chdir($htpasswd_directory) or die "Can not change directory to the $htpasswd_directory!";
  
  my $cat_user = `cat $htpasswd_file | grep $nagios_user_create`;
  if (length($cat_user) > 0) {
   print "User has record in $htpasswd_file file which may mean that user can exists. Exit program\n";
   exit;
  }
  
  tie my @array, 'Tie::File', $htpasswd_file or die "Reading file $htpasswd_file finished with an error : $!\n";
  my $monkey_index = index($array[-1], '@');
  my $domain_substring = substr($array[-1], $monkey_index, length($array[-1]));
  my $new_user_string = $nagios_user_create.$domain_substring;
  print "Adding record to $htpasswd_file file : $new_user_string\n";
  open (FILE, ">>$htpasswd_file") || die "Error opening file $htpasswd_file : $!\n";
  print FILE "$new_user_string\n";
  close FILE;
 } else {
  print "Catalog $htpasswd_directory does not exist. Exit program\n";
  exit;
 }
}

sub duplicate_st1monms2_cgi {
 my ($nagios_user_create) = @_;
 if (-d $nagios_cgi_directory) {
  chdir($nagios_cgi_directory) or die "Can not change directory to the $nagios_cgi_directory!";
  
  my $cat_user = `cat $nagios_cgi_cfg_file | grep $nagios_user_create`;
  if (length($cat_user) > 0) {
   print "User has record in $htpasswd_file file which may mean that user can exists. Exit program\n";
   exit;
  }

  open ( FILE, "$nagios_cgi_cfg_file" ) || die "Error opening file $nagios_cgi_cfg_file : $!\n";
  my @lines = ;
  for my $linia (@lines) {
   foreach my $field (@nagios_cgi_fields) {
    if($linia =~ /$field/){
     $linia =~ s/^\s+//;
     $linia =~ s/\s+$//;
     $linia =~ s/^\s+//;
     $linia =~ s/\s+$//;
     
     my @add_user_authorizate = `sed -i.bak -e s/$linia/$linia$comma$nagios_user_create$domain/g $nagios_cgi_cfg_file`;
     print @add_user_authorizate;
     
     print "Granted $field privilege to user $nagios_user_create\n";
    }
   }
  }
  close (FILE);
 } else {
  print "Catalog $nagios_cgi_directory does not exist. Exit program\n";
  exit;
 }
}

sub restart_nagios {
 my @restart = `mon restart`;
 print @restart;
}

sub merlin_db_operations {
 my ($nagios_user_create) = @_;
 
 print "Checking if user $nagios_user_create$domain exists in database already\n";
 my $sthUserExists = $dbh->prepare('select count(*) as ilosc from users where username = ?') || die "Database Select User Error $DBI::errstr";
 $sthUserExists->bind_param(1, $nagios_user_create.$domain);
 $sthUserExists->execute();
 my $ifexists = $sthUserExists->fetchrow_hashref();
 
 if ($ifexists->{ilosc} > 0) {
  print "User $nagios_user_create$domain exists! Interrupt program!\n";
  $dbh->disconnect();
  exit;
 } else {
  print "User $nagios_user_create$domain does not exist in database. Continuing.\n";
 }

 my $sth = $dbh->prepare('select max(id) as maxid from users') || die "Database Select Max ID Error $DBI::errstr";
 $sth->execute();
 my $result = $sth->fetchrow_hashref();
 my $new_user_id = $result->{maxid} + 1;

 print "Please give name of user (realname)\n";
 my $realname = <>;
 chomp ($realname);
 print "Please give e-mail address of user (e-mail)\n";
 my $email = <>;
 chomp ($email);
 
 my $sthUserTable = $dbh->prepare('insert into users(id, realname, email, username, password_algo, password) VALUES (?, ?, ?, ?, ?, ?)');
 $sthUserTable->bind_param(1, $new_user_id);
 $sthUserTable->bind_param(2, $realname);
 $sthUserTable->bind_param(3, $email);
 $sthUserTable->bind_param(4, $nagios_user_create.$domain);
 $sthUserTable->bind_param(5, $password_algorithm);
 $sthUserTable->bind_param(6, $password_user_merlin);
 $sthUserTable->execute();
 
 print "Added to Users table a user (username) : $nagios_user_create$domain with ID = $new_user_id\n";
 print "Selected algorithm for password : $password_algorithm and password : $password_user_merlin\n";
 
 print "Adding roles for user\n";
 my $sthRolesUsersTable = $dbh->prepare('insert into roles_users(user_id, role_id) VALUES (?, 1)');
 $sthRolesUsersTable->bind_param(1, $new_user_id);
 $sthRolesUsersTable->execute();
 
 print "Please answer for user roles : \n";
 print "Add system_information role ? (0 - no, 1 - yes)\n";
 my $system_information = <>;
 chomp ($system_information);
 print "Add configuration_information role ? (0 - no, 1 - yes)\n";
 my $configuration_information = <>;
 chomp ($configuration_information);
 print "Add system_commands role ? (0 - no, 1 - yes)\n";
 my $system_commands = <>;
 chomp ($system_commands);
 print "Add all_services role ? (0 - no, 1 - yes)\n";
 my $all_services = <>;
 chomp ($all_services);
 print "Add all_hosts role ? (0 - no, 1 - yes)\n";
 my $all_hosts = <>;
 chomp ($all_hosts);
 print "Add all_service_commands role ? (0 - no, 1 - yes)\n";
 my $all_service_commands = <>;
 chomp ($all_service_commands);
 print "Add all_host_commands role ? (0 - no, 1 - yes)\n";
 my $all_host_commands = <>;
 chomp ($all_host_commands);
 
 print "Adding roles for user $nagios_user_create\n";
 my $sthUserAuthorizationTable = $dbh->prepare('insert into ninja_user_authorization(user_id, system_information, configuration_information, system_commands, all_services, all_hosts, all_service_commands, all_host_commands) 
  VALUES (?, ?, ?, ?, ?, ?, ?, ?)');
 $sthUserAuthorizationTable->bind_param(1, $new_user_id);
 $sthUserAuthorizationTable->bind_param(2, $system_information);
 $sthUserAuthorizationTable->bind_param(3, $configuration_information);
 $sthUserAuthorizationTable->bind_param(4, $system_commands);
 $sthUserAuthorizationTable->bind_param(5, $all_services);
 $sthUserAuthorizationTable->bind_param(6, $all_hosts);
 $sthUserAuthorizationTable->bind_param(7, $all_service_commands);
 $sthUserAuthorizationTable->bind_param(8, $all_host_commands);
 $sthUserAuthorizationTable->execute();
}

sub help {
   print "\nAdd User Nagios\n";
   usage();
   print < \$help,
  'u=s'   => \$new_nagios_user,     'nagios_user:s'  => \$new_nagios_user,
  'dbu=s'   => \$username_db,               'username_db:s'    => \$username_db,
  'dbp=s'   => \$password_db,      'password_db:s'  => \$password_db,
  'dbd=s'   => \$database,       'database:s'   => \$database
    );

if ($help) { help(); exit; }
if (!defined($new_nagios_user))
 { print "Put new username nagios to create! (-h for help)\n"; usage(); exit;}
if (!defined($username_db) || !defined($password_db))
    { print "Put database login or password info! (-h for help)\n"; usage(); exit;}
if (!defined($database))
    { print "Put database name! (-h for help)\n"; usage(); exit;}
}

######### MAIN PROGRAM

check_input();

######### Connect to merlin database
print "Checking connection to database $database\n";
connect_db_merlin();

######### Duplicate user field on  in /opt/nagios/etc/htpasswd.users
print "Duplicate user entry in file $htpasswd_directory$htpasswd_file\n";
duplicate_htpasswd($new_nagios_user);

######### Adding authorization to file /opt/nagios/etc/cgi.cfg
print "Adding authorizations for new user to file $nagios_cgi_directory$nagios_cgi_cfg_file\n";
duplicate_st1monms2_cgi($new_nagios_user);

######### Restarting nagios
print "Restarting nagios... please wait\n";
restart_nagios();

######### Adding records to database
print "Adding records to database\n";
merlin_db_operations($new_nagios_user);

######### Disconnect from database
print "Disconnect from database\n";
$dbh->disconnect();

Reference : [1] Pastebin GarciaPL Add User Nagios [2] Nagios Docs [3] Diknowstech Blog How To Change Nagios Password

HP Data Protector Reports

by GarciaPL on Wednesday 21 August 2013

Many many years ago on the one of the intern I have created a small tool to create reports about backups of Oracle and File System in company using HP Data Protector. Below I put a printscreen of output file :

HP Data Protector Report


And the final script code to create HP Data Protector reports :

use Date::Calc;
use Spreadsheet::WriteExcel;
use Spreadsheet::WriteExcel::Utility;

sub help_syntax {
 print "\nHelp Syntax :\n\n";
 print "Backuped FileSystems and Oracle (default) -> perl script_name.pl\n";
 print "Backuped FileSystems and Oracle in .xls format -> perl script_name.pl --xls\n";
 print "Backuped FileSystems -> perl script_name.pl --FS\n";
 print "Backuped FileSystems in format .xls -> perl script_name.pl --FS --xls\n";
 print "Backuped Oracle -> perl script_name.pl --Oracle\n";
 print "Backuped Oracle in format .xls -> perl script_name.pl --Oracle --xls\n\n";
}

$boolean_only_FS=0;
$boolean_only_Oracle=0;
$boolean_only_xls=0;

if ( scalar(@ARGV) > 2 )
{
 print "Numer of arguments is incorrect (max 2)\n";
 &help_syntax;
 exit;
}

my $workbook;
my $worksheet;
my ($x,$y)=(0,0);
my $glowny_licznik=0;

sub xls_function {

 $workbook = Spreadsheet::WriteExcel->new('output.xls');
 $worksheet = $workbook->add_worksheet('Backups');
 $format = $workbook->add_format();
 $format->set_bold();
 $format->set_align('center');
 $format->set_fg_color('grey');
 $format->set_size(12);
 $format->set_color('black');
 $worksheet->set_column(0,0,20);
 $worksheet->set_column(1,1,30);
 $worksheet->set_column(2,2,7);
 $worksheet->set_column(3,3,40);
 $worksheet->set_column(4,4,13);
 $worksheet->set_column(5,5,15);
 $worksheet->set_column(6,6,18);
 $worksheet->write(0,0,"Session",$format);
 $worksheet->write(0,1,"Server",$format);
 $worksheet->write(0,2,"Type",$format);
 $worksheet->write(0,3,"Backuped filesystems",$format);
 $worksheet->write(0,4,"Time start",$format);
 $worksheet->write(0,5,"Duration",$format);
 $worksheet->write(0,6,"Data GB",$format);
}

@lista_argumentow;
foreach (@ARGV) {
 push(@lista_argumentow,$_);
}

if ( @lista_argumentow[0] eq "--help" || @lista_argumentow[0] eq "-help" || @lista_argumentow[0] eq "/h" || @lista_argumentow[0] eq "help" )
{
 &help_syntax;
 exit;
}
elsif ( @lista_argumentow[0] eq "--xls" and @lista_argumentow[1] eq "" )
{
 $boolean_only_xls=1;
 $boolean_only_FS=1;
 $boolean_only_Oracle=1;
 &xls_function;
}
elsif ( @lista_argumentow[0] eq "--FS" and @lista_argumentow[1] eq "--xls" )
{
 $boolean_only_xls=1;
 $boolean_only_FS=1;
 
 &xls_function;
}
elsif ( @lista_argumentow[0] eq "--Oracle" and @lista_argumentow[1] eq "--xls" )
{
 $boolean_only_xls=1;
 $boolean_only_Oracle=1;
 
 &xls_function;
}
elsif ( @lista_argumentow[0] eq "--FS" and @lista_argumentow[1] eq "" )
{
 $boolean_only_FS=1;
}
elsif ( @lista_argumentow[0] eq "--Oracle" and @lista_argumentow[1] eq "" )
{
 $boolean_only_Oracle=1;
}
elsif ( scalar(@ARGV) eq 0 )
{
 $boolean_only_Oracle=1;
 $boolean_only_FS=1;
}
else
{
 &help_syntax;
 exit;
}

###################################################################################

$omniback_path="D:/HP/OmniBack/bin";

chdir($omniback_path) or die "Cannot open path $omniback_path\n";

if (-e "omnirpt.exe" ) {
 print "Found omnirpt.exe\n";
}
else {
 print "File omnirpt.exe does not exist. Exit program.\n";
 exit;
}

$lista_sesji_command=`omnirpt.exe -report list_sessions -timeframe 24 24`;

open FILE, ">session_list.txt" or die $!; #print list of session for Oracle and FileSystem
print FILE $lista_sesji_command;
close FILE;
print "Created session list in file session_list.txt\n";

if (-e "session_list.txt")
{
open (CHECKBOOK, "output.txt');

$count = 0;
$count_oracle=0;

while ($record = ) {
  @tokens = split(/\s+/, $record);
  my $boolean = 0;
  $count_oracle=0;
  $count=$count+1;
  foreach my $token (@tokens) {
   if ( @tokens[2] ne "Oracle8" and $boolean_only_FS eq 1)
   {
    if ( $boolean eq 0 )
    {
     if( @tokens[15] ne "Errors" )
     {
      if( @tokens[15] ne "" )
      {
       print "\n----FileSystem----\n";
       print "Session : ",@tokens[2],"\n";
       print "Time start : ",@tokens[6],"\n";
       print "Duration : ",@tokens[8],"\n";
       print "Data GB : ",@tokens[9],"GB\n";
       print "SessionID : ",@tokens[15],"\n";
       
       $temp_session_ID=@tokens[15];
       $session_objects=`omnirpt.exe -report session_objects -session $temp_session_ID`;
       $licz=0;
       $temp_host;
       $temp_host2;
       $boolean_session=1;
       $flaga_rowne=1;
       $flaga_nierowne=1;
       
       @tokens_session_objects = split(/\s+/, $session_objects);
       foreach my $token_session (@tokens_session_objects) {
        $licz=$licz+1;
        $temp_host=@tokens_session_objects[$licz];
        
        if( $token_session =~ m/FileSystem/)
        {
          $glowny_licznik = $glowny_licznik + 1;
        
          if ( $boolean_session )
          {
           $temp_host2=$temp_host;
          }

          ####################################################################################       

          if ( $boolean_session )
          {
           print PLIK_WYNIKOWY @tokens[2]," ";   #Session (once)
           
           if ( $boolean_only_xls ) 
           {
            $worksheet->write($glowny_licznik,0,@tokens[2]);
           }
          }
          if ( $boolean_session )
          {
           print PLIK_WYNIKOWY " ",@tokens_session_objects[$licz]," ";  #host
           
           if ( $boolean_only_xls ) 
           {
            $worksheet->write($glowny_licznik,1,@tokens_session_objects[$licz]);
           }
          }
          else
          {
           print PLIK_WYNIKOWY "  ",@tokens_session_objects[$licz]," ";  #host
           
           if ( $boolean_only_xls ) 
           {
            $worksheet->write($glowny_licznik,1,@tokens_session_objects[$licz]);
           }
          }
          
          if ( @tokens_session_objects[$licz] eq $temp_host2 and $flaga_rowne == 1)  #hosts name are the same
          {
           if ( $boolean_session )
           {
            print PLIK_WYNIKOWY "FS","  ";  
            
            if ( $boolean_only_xls ) 
            {
             $worksheet->write($glowny_licznik,2,"FS");
            }
            
           }
          }
          if ( @tokens_session_objects[$licz] ne $temp_host2 and $flaga_nierowne == 1) #different host names
          {
           if ( $boolean_session )
           {
            print PLIK_WYNIKOWY "FS","  "; 
            
            if ( $boolean_only_xls ) 
            {
             $worksheet->write($glowny_licznik,2,"FS");
            }
           }
          }
          
          
          if ( $boolean_session )
          {
           print PLIK_WYNIKOWY @tokens_session_objects[$licz+1],"  "; #Backuped filesystems
           
           if ( $boolean_only_xls ) 
           {
            $worksheet->write($glowny_licznik,3,@tokens_session_objects[$licz+1]);
           }
          }
          else
          {
           print PLIK_WYNIKOWY @tokens_session_objects[$licz+1],"\n"; #Backuped filesystems
           
           if ( $boolean_only_xls ) 
           {
            $worksheet->write($glowny_licznik,3,@tokens_session_objects[$licz+1]);
           }
          }
          
          
          if ( @tokens_session_objects[$licz] eq $temp_host2 and $flaga_rowne == 1)  #host names are the same
          {
           if ( $boolean_session )
           {
            print PLIK_WYNIKOWY @tokens[6]," ";       #Time start (once)
            print PLIK_WYNIKOWY @tokens[8]," ";       #Duration (once)
            print PLIK_WYNIKOWY @tokens[9],"GB\n";       #Data GB (once)
            $boolean_session=0;
            
            if ( $boolean_only_xls ) 
            {
             $worksheet->write($glowny_licznik,4,@tokens[6]);
             $worksheet->write($glowny_licznik,5,@tokens[8]);
             $worksheet->write($glowny_licznik,6,"@tokens[9] GB");
            }
           }
          
           $flaga_rowne=0;
           $flaga_nierowne=1;
          }
          if ( @tokens_session_objects[$licz] ne $temp_host2 and $flaga_nierowne == 1) #different host names
          {
           if ( $boolean_session )
           {
            print PLIK_WYNIKOWY @tokens[6]," ";       #Time start (once)
            print PLIK_WYNIKOWY @tokens[8]," ";       #Duration (once)
            print PLIK_WYNIKOWY @tokens[9],"GB\n";       #Data GB (once)
            $boolean_session=0;
            
            if ( $boolean_only_xls ) 
            {
             $worksheet->write($glowny_licznik,4,@tokens[6]);
             $worksheet->write($glowny_licznik,5,@tokens[8]);
             $worksheet->write($glowny_licznik,6,"@tokens[9] GB");
            }
           }
           
           $flaga_nierowne=0;
           $flaga_rowne=1;
          }
          
          $temp_host=@tokens_session_objects[$licz];
          $temp_host2=@tokens_session_objects[$licz];
        }
       }
       print "\n";
       $boolean = 1;
      }
     }
    }
   }
   elsif ( $boolean_only_Oracle eq 1 ) #in the session found Oracle8
   {
    $temp_session_oracle=@tokens[16];     #sessionID
    $oracle=`omnidb.exe -session $temp_session_oracle`;
    @tokens_oracle8 = split(/\s+/, $oracle);
    my $boolean_check=1;

    foreach my $token_oracle (@tokens_oracle8) {

     if( $token_oracle =~ m/.dbf/ and $boolean_check eq 1) #one host - one SID
     {
      $glowny_licznik = $glowny_licznik + 1;
     
      $znak_mniejszosci=rindex($token_oracle,'<');
      $podkreslenie=rindex($token_oracle,'_');
      $SID_Bazy=substr($token_oracle,$znak_mniejszosci+1,$podkreslenie-$znak_mniejszosci-1);
 
      $dwukropek=index($token_oracle,':');
      $Host=substr($token_oracle,0,$dwukropek);

      print "\n----Oracle8----\n";
      print "Session : ",@tokens[3],"\n";
      print "Time start : ",@tokens[7],"\n";
      print "Duration : ",@tokens[9],"\n";
      print "Data GB : ",@tokens[10],"GB\n";
      print "SessionID : ",@tokens[16],"\n";
      print "SID Bazy : ",$SID_Bazy,"\n";
      
      #write to output file

      print PLIK_WYNIKOWY @tokens[3]," "; #Session
      print PLIK_WYNIKOWY $Host,"  ";  #Host 
      print PLIK_WYNIKOWY "Oracle","  "; #Oracle
      print PLIK_WYNIKOWY $SID_Bazy,"  ";  #Database SID
      print PLIK_WYNIKOWY @tokens[7]," "; #Time start
      print PLIK_WYNIKOWY @tokens[9]," "; #Duration
      print PLIK_WYNIKOWY @tokens[10],"GB\n"; #Data GB
      
      if ( $boolean_only_xls ) 
      {
       $worksheet->write($glowny_licznik,0,@tokens[3]);
       $worksheet->write($glowny_licznik,1,$Host);
       $worksheet->write($glowny_licznik,2,"Oracle");
       $worksheet->write($glowny_licznik,3,$SID_Bazy);
       $worksheet->write($glowny_licznik,4,@tokens[7]);
       $worksheet->write($glowny_licznik,5,@tokens[9]);
       $worksheet->write($glowny_licznik,6,"@tokens[10] GB");
      }
      
      $boolean_check=0;
     }
    
    }
    print "\n";
    last;
   }
  }
  $boolean = 1;
}
close(CHECKBOOK);
close(PLIK_WYNIKOWY);
}
else {
print "File session_list.txt does not exist";
}

if ( $boolean_only_xls eq 1 ) {
 $workbook->close();
}


Reference :  [1] Pastebin GarciaPL HP Data Protector [2] Wikipedia HP Data Protector [3] HP Data Protector Resources

Review Instant Nagios Starter

by GarciaPL on Saturday 10 August 2013

In the last days I received a very interesting offer to write down some words about book entitled "Instant Nagios Starter". I received this book from a publishing company called Packt.
First of all, I must to say that book is very helpful for all kind of IT specialists who would like to run Nagios in theirs companies or homes. It describes all major topics which you are going to face with while Nagios installation. I really would like to recommend this book. Very quick, rich content quide!


I would like to also share my review on Goodreads.com which is :

"If you are looking for well-written and the most smallest with rich content guide which help you to quick start Nagios system in your environment you are in the right place. Instant Nagios Starter is dedicated for administrators, developers and even IT enthusiasts. Arrangement of chapters is correct and logical which makes that understanding of Nagios is pretty easy."

Reference :  [1] Packtpub.com Instant Nagios Starter [2] Goodreads.com Instant Nagios Starter Review

Killing processes contain pattern

by GarciaPL

I would like to share, in my opinion, quite helpful tool dedicated for Linux administrators for ending (or some of you would say "killing") processes which contain particular pattern. I prepared a dedicated script written in Perl which is very easy to help. If you would like to kill all processes contain word "chrome" just run like this one : ./KillProcesses.pl -p chrome. I also wrote a small program with infinity loop which can be used for testing purposes. It can be found using pattern LoopProcess.

KillProcesses.pl

#!/usr/bin/perl -w

use strict;
use warnings;
use Getopt::Long;
use Data::Dumper;

my $help;
my $process_pattern = undef;

sub kill_processes {
 if (defined($process_pattern)) {
  my @processeslist = `ps -ef | grep $process_pattern | grep -v grep | awk '{print \$2}'`;

  if ((@processeslist) and (scalar(@processeslist) > 1)) {
   print "\nKilling processes with PID like : \n";
   print @processeslist;
   my @killprocess = `kill -9 @processeslist`;
   print Dumper @killprocess;
  } else {
   print "\nCan not find processes contain a pattern '$process_pattern'\n";
  }
 } else {
  print "\nProcess name was not defined\n";
 }
}

sub usage {
    print "$0 -p \n";
}

sub help {
   print "\nKill All Processes along with pattern\n";
   usage();
   print < \$help,
  'p=s'  => \$process_pattern,   'pattern=s' => \$process_pattern
    );

if ($help) { help(); exit; }
if (!defined($process_pattern))
    { print "Put pattern of process! (-h for help)\n"; usage(); exit;}
}

######### MAIN PROGRAM

check_input();

######## KILL PROCESSES ALONG WITH PATTERN
print "\nSearching and ending processes contain a pattern '$process_pattern'";
kill_processes();


LoopProcess.pl

#!/usr/bin/perl -w

use strict;
use warnings;

while (1) {

}


Reference :  [1] GarciaPL Pastebin KillProcesses [2] GarciaPL Pastebin LoopProcess

VBA Replace string order

by GarciaPL on Sunday 28 July 2013

I would like to share with you a small VBA macro which basic functionality is just replace order of two-member string for example :

John Travolta   ->   Travolta John

Short manual of macro :
1. Select cells you want to replace the order of their content
2. Run macro

Macro code :

Public Function StrRange(ByVal nRow As Single, ByVal nCol As Single) As String
        Dim sC As String
        Dim nC, nRest, nDivRes As Integer
       
        sC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        nC = Len(sC)
       
        nRest = nCol Mod nC
        nDivRes = (nCol - nRest) / nC
       
        If nDivRes > 0 Then StrRange = Mid(sC, nDivRes, 1)
        StrRange = StrRange & Mid(sC, nRest, 1) & Format(nRow)
End Function
 
Sub ChangeString()
 
    Dim range As String
    range = Selection.Address(ReferenceStyle:=xlA1, _
                           RowAbsolute:=False, ColumnAbsolute:=False)
     
    If range = "" Then
        MsgBox ("The range of cells was not definedcells. Ending the macro")
        Exit Sub
    End If
   
    Dim Start
    Dim Last
    intPos = InStr(1, range, ":")
    If intPos > 0 Then
        split_string = Split(range, ":")
        If UBound(split_string) = 1 Then
            Start = split_string(0)
            Last = split_string(1)
        End If
    Else
        Start = range
        Last = Start
    End If
   
    Dim SheetName
    SheetName = ActiveSheet.Name
    If SheetName = "" Then
        MsgBox ("Cannot read sheet name. Ending the macro")
        Exit Sub
    End If
   
    Dim CellAddress
    For Each c In Range("" & CStr(Start) & ":" & "" & CStr(Last))
        If c.Value <> "" Then
            CellContent = Split(c.Value, " ")
            CellAddress = StrRange(c.Row, c.Column)
 
            Dim wb As Workbook
            Dim ws As Worksheet
            Dim TxtRng  As Range
            Set wb = ActiveWorkbook
 
            Set ws = wb.Sheets(SheetName)
            Set TxtRng = ws.Range("" & CStr(CellAddress))
            TxtRng.Value = CStr(CellContent(1)) & " " & CStr(CellContent(0))
        End If
    Next c
       
End Sub

Reference :
[1] Pastebin GarciaPL VBA Replace string order

Nagios verify configuration

by GarciaPL on Tuesday 16 July 2013

If you would like to verify Nagios configuration just run this command :

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Of course in your case the path to nagios.cfg may be different ;)


Reference :
[1] Nagios Verify Configuration

LaTeX Business Card

by GarciaPL

Quick and very simple piece of code in LaTeX which I suppose help you to create very ordinary own business card ;)

LaTeX Business Card


\documentclass[11pt]{article}
 
\usepackage[english]{babel}
\usepackage{polski}
\usepackage[cp1250]{inputenc}
\usepackage[none]{hyphenat}
\usepackage{graphicx}
 
\begin{document}
 
\begin{titlepage}
 
\newcommand{\HRule}{\rule{\linewidth}{0.5mm}} % Defines a new command for the horizontal lines, change thickness here
 
\center % Center everything on the page
 
%----------------------------------------------------------------------------------------
%       HEADING SECTIONS
%----------------------------------------------------------------------------------------
 
%\textsc{\LARGE Dane rachunku bankowego}\\[1.5cm] % Name of your university/college
%\textsc{\Large Major Heading}\\[0.5cm] % Major heading such as course name
%\textsc{\large Minor Heading}\\[0.5cm] % Minor heading such as course title
 
%----------------------------------------------------------------------------------------
%       TITLE SECTION
%----------------------------------------------------------------------------------------
 
\HRule \\[0.7cm]
{ \huge \bfseries Company Name}\\[0.4cm]
\HRule \\[0.9cm]
 
%----------------------------------------------------------------------------------------
%       AUTHOR SECTION
%----------------------------------------------------------------------------------------
 
\large\emph{Details About Company}\\\vspace{0.5cm}
\large\emph{Facebook.com/CompanyPage }\\\vspace{0.5cm}
\large\emph{Twitter.com/CompanyPage}\\\vspace{0.5cm}
 
%----------------------------------------------------------------------------------------
 
\vfill % Fill the rest of the page with whitespace
 
\end{titlepage}
\end{document}



Reference :
[1] Business Card GarciaPL Pastebin.com

Send mail in Perl

by GarciaPL on Sunday 7 July 2013

I would like to share with you a small script written in Perl which simply send an email. You can use it in your other scripts when you want to indicate an error while something goes wrong. Of course this small piece of code can be also used in Nagios scripts ;) Only imagination is the limit where this sending email function can be used.

sub sendEmail {
        my ($to, $from, $subject, $message) = @_;
        my $sendmail = '/usr/lib/sendmail';
        open(MAIL, "|$sendmail -oi -t");
        print MAIL "From: $from\n";
        print MAIL "To: $to\n";
        print MAIL "Subject: $subject\n\n";
        print MAIL "$message\n";
        close(MAIL);
}
 
sendEmail("receiveremail\@domain.com", "myemail\@domain.com", "Nagios Error", "Cannot receive NRPE output from host 10.100.5.6");

Reference : 
[1] Pastebin GarciaPL Send email in Perl

Automate mount directory

by GarciaPL on Tuesday 7 May 2013

I would like to introduce a small script written in Python which allows to automate mount unmounted specified directory. Script can be placed in crontab. User should define command, password which is required for this command, path to directory which should be mounted and expected text as usual after executing specified command. You can also make further adjustments of script if your command does not need for instance password.

Script uses modules :

  • pexpect
  • time
  • datetime
  • os
https://pastebin.com/7gHaMmeR

ORA-01861: literal does not match format string

by GarciaPL on Thursday 2 May 2013

In last few days I had a problem with some SQL queries in Oracle database. I won't give you this particular SQL query which has ended with error which you can find in the header of this post, but i will give solution! :)

Suppose that your SQL queries use data in format for instance YYYY-MM-DD, so before them execute below command which specifies the default date format which can be used in TO_CHAR and TO_DATE functions :

alter session  set NLS_DATE_FORMAT='YYYY-MM-DD';


Reference :
[1] Docs Oracle NLS_DATE_FORMAT

Nagios plugins support

by GarciaPL on Tuesday 30 April 2013

Some of you may noticed that I made few posts about Nagios plugins which were made by me ;)

1) Monitor Cisco HSRP with SNMP
2) Nagios HP BladeSystem Ambient Temperature
3) CPUMem Cisco 2800 plugin Nagios Exchange

Second and third script you can of course find at Nagios Exchange.

I would like also to tell that if you have some bright or casual idea about new plugin for Nagios or your company needs to write some plugins and integrate them with existed Nagios infrastructure, please just write to me ;) I will help you of course in telecommute way ;) Contact information you will be able to find in About me section of this blog.

Nagios | The Industry Standard in IT Infrastructure Monitoring

Orange API Hackathon

by GarciaPL on Thursday 25 April 2013

So! A new competition has arrived! It is called Orange API Hackathon! It is dedicated to developers and people with bright ideas about new applications, systems and services which must use one of the available Open Middleware Application Programming Interfaces which are provided by Orange and Town Hall of Warsaw (Find out where this town is! and Check Town Hall Website).

This contest is divided into two stages :

Stage 1) Collection of Abstracts (11 April 2013 - 3 June 2013)
Stage 2) Implementation and Selection (15 June May 2013 - 25 June 2013)

Awards :

- Grand Prize : invitation for one to Java One Conference 2013
- First Prize : summer internships in Orange Labs for 3 participants for 3 months


I think that very interesting and for some very useful information is that one of the partner of contest which is a IQ Partners SA is going to setting aside a pool of 500 000 PLN (about 120 000 Euros) to create a company with one or more winners of Orange API Hackathon.

Reference :
[1] Open Middleware Orange API Hackathon Contest Details
[2] Terms & Conditions of Contest [English]
[3] Terms & Conditions of Contest [Polish]
[4] Town Hall of Warsaw
[5] IQ Partners SA

Perl Check for Business Days with DateTime module

by GarciaPL

Quick piece of code how to check if given date in DateTime module format is business day or not ;) I think that this function is very usefull for every kind of business application that you would like to write in the near future ;)

my @day_of_week = ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday');

sub check_business_day {
 my ($name_of_day) = @_;
 if ( grep( /^$name_of_day$/, @day_of_week ) ) {
  return 1;
 } else {
  return 0;
 }
}

check_business_day($date_time->day_name());

Function returns 1 if given day name from $date_time variable is a business day, otherwise it return 0.

Reference :
[1] Source Pastebin.com

OpenAPI Note from the meeting 06.11.2012

by GarciaPL on Saturday 16 March 2013

In recently times appeared on Institute of Telecommunication (Instytut Łączności) website a new note from the meeting which was took place at 6th September 2012.

Business entities which were present : Institute of Telecommunication, Orange, Play, T-Mobile, Plus, MLife.

Discussed issues :

The following interfaces (APIs) will be standardized :

  • SMS, MMS, USSD
  • Click to call
  • MNP
  • Location
  • Permission
  • oAuth2
  • Active Subscription
  • RBT API, Voice Mail API etc.

Those list is not finally closed. It can be modified.

Those above APIs will be exposed as Web Services in REST style.

Next meeting will take place at Plus headquarters. Stay tuned!



Reference :
[1] Institute of Communications (Instytut Łączności)
[2] Home page of OpenAPI initiative [Polish/English]
[3] Institute of Telecommunication Note from meeting 06.11.2012 (pdf) [Polish]

OpenAPI Letter of intent

by GarciaPL

I'm so sorry for my late in informing you about new information about great project called OpenAPI which was initiated by the Institute of Telecommunication (Instytut Łączności) and major telecom operators for instance Orange, Plus, T-Mobile and Play which cooperates in Poland.

Those business entities and Institute of Telecommunication signed a letter of intent which gave opportunity to participate in the project (OpenAPI) for others business entities.

Every company interested in this cooperation should contact with Jordi Mongay Batalla (email).




Reference :
[1] Institute of Communications (Instytut Łączności)
[2] Letter of Intent (pdf) [Polish]
[3] Home page of OpenAPI initiative [Polish/English]

Google Maps JSP in Spring

by GarciaPL on Thursday 14 March 2013


I had a small issue with adding dynamically markers which were stored in database (mongodb) to google map which was placed on JSP page in Spring application. I hope that someone could use it too own purposes ;)

        
        


Reference :
[1] Pastebin Source
[2] Stackoverflow.com Google Maps JSP in Spring
[3] Google Groups Warszawa JUG

CPUMem Cisco 2800 plugin Nagios Exchange

by GarciaPL on Friday 1 March 2013


Next script to Nagios Exchange has arrived! This one will allow you to check CPU (in 5 min, 1 min and 5 sec period) and Memory (Free and Used Pool) of router Cisco 2800 Series

Nagios Exchange CPU Mem Cisco 2800

Nagios | The Industry Standard in IT Infrastructure Monitoring

HP BladeSystem plugin Nagios Exchange

by GarciaPL on Friday 1 February 2013


I would like to give you a link to Nagios Exchange site where was published my plugin to check ambient temperature in HP BladeSystem . More information after clicking link below :

Nagios Exchange HP BladeSystem Ambient Temperature

Nagios | The Industry Standard in IT Infrastructure Monitoring