Sunday, October 26, 2014

Princess cat

Saturday, October 25, 2014

Google Drive python uploader, Invalid user credentials given.

pi@raspberrypi ~ $ python uploader.py gn.cfg sp66704.exe
Invalid user credentials given.
To solve this situation you must log into google account and enable "Access for less secure apps"

Enable this setting:

Friday, October 24, 2014

Create trigger, Free disk space is less than n GB, zabbix


For 5GB trigger copy to the title
Free disk space is less than 5GB on volume {#FSNAME} ({ITEM.VALUE2})
Copy to the Expression
{Template OS Windows:vfs.fs.size[{#FSNAME},free].last(0)}<5400000000 and {Template OS Windows:vfs.fs.size[{#FSNAME},free].last(0)}>2148000000 and {Template OS Windows:vfs.fs.size[{#FSNAME},free].last(0)}

For 2GB trigger copy to the title
Free disk space is less than 2GB on volume {#FSNAME} ({ITEM.VALUE2})
Copy to the Expression
{Template OS Windows:vfs.fs.size[{#FSNAME},free].last(0)}<2148000000 and {Template OS Windows:vfs.fs.size[{#FSNAME},free].last(0)}

Best practice to periodically update flash player, GP

1) Share a network destination with write permissions for system acount and also allow "Domain Computers" collection to write to this destination. This will be the destination where log files are created.
\\status\log\AdobeFlashPlayer
2) Get the latest adobe flash player installers. These links always stands for latest version
http://fpdownload.macromedia.com/pub/flashplayer/latest/help/install_flash_player_ax.exe
http://fpdownload.macromedia.com/pub/flashplayer/latest/help/install_flash_player.exe
I gues it is good to have only one place where you keep latest flash player installer. Let it be your public install server:
\\public\install\AdobeFlashPlayer
3) Create installer script. This will update flash player only for Windows XP and Windows 7
install-flash-player.cmd:
@echo off
set m=HKLM\SOFTWARE\Macromedia
set l=\\status\log\AdobeFlashPlayer
setlocal EnableDelayedExpansion
if not exist "%l%\%computername%.log" (
ver | find "Version 6.1" > nul 2>&1
if !errorlevel!==0 (
echo Windows 7 detected
goto win7
)
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" ^
/v ProductName | find "Windows XP" > nul 2>&1
if !errorlevel!==0 (
echo Windows XP detected
goto winxp
)
goto exit

:winxp
:win7
echo %date% %time%
echo installing plash player for internet explorer
start /wait "" "%~dp0install_flash_player_ax.exe" -install
reg query %m%\FlashPlayerActiveX /v Version | find "Version" > "%l%\%computername%.log"
echo installing plash player for firefox, opera, etc
start /wait "" "%~dp0install_flash_player.exe" -install
reg query %m%\FlashPlayerPlugin /v Version | find "Version" >> "%l%\%computername%.log"
)

:exit

echo.
endlocal
4) Create a computer startup script for "Domain Computers" collection and re-call the flash player installer
call "\\public\install\AdobeFlashPlayer\install-flash-player.cmd"
Everty time the new flash player comes out you must only overwrite install_flash_player_ax.exe and install_flash_player.exe in a public installation directory and delete all log files.

If want to automatize also this process you can create schedulled task. In this script you need wget and md5sum
refresh-latest-version.cmd:
@echo off
set l=\\status\log\AdobeFlashPlayer
setlocal EnableDelayedExpansion
"%~dp0wget.exe" http://fpdownload.macromedia.com/pub/flashplayer/latest/help/install_flash_player_ax.exe -O%~dp0install_flash_player_ax.exe.new
"%~dp0wget.exe" http://fpdownload.macromedia.com/pub/flashplayer/latest/help/install_flash_player.exe -O%~dp0install_flash_player.exe.new
for /f "tokens=1" %%a in ('%~dp0md5sum.exe %~dp0install_flash_player.exe.new') do (
%~dp0md5sum.exe %~dp0install_flash_player.exe | findstr %%a
if not !errorlevel!==0 (
xcopy %~dp0install_flash_player.exe.new %~dp0install_flash_player.exe /Y
)
del %~dp0install_flash_player.exe.new /F /Q
)
for /f "tokens=1" %%a in ('%~dp0md5sum.exe %~dp0install_flash_player_ax.exe.new') do (
%~dp0md5sum.exe %~dp0install_flash_player_ax.exe | findstr %%a
if not !errorlevel!==0 (
xcopy %~dp0install_flash_player_ax.exe.new %~dp0install_flash_player_ax.exe /Y
del %l%\*.* /Q /F
)
del %~dp0install_flash_player_ax.exe.new /F /Q
)
endlocal
del %l%\*.* /Q /F is only set once in ActiveX version of flash player so the detection rule at the end depends only if this version is changed.

Everytime you run refresh-latest-version.cmd it downloads version of flash player which today is the latest. Then it compares old installer with current and if it is not the same then overwrite the installer.

Wednesday, October 22, 2014

My favourite pointers challenge


int a=3, b=4, c=5;
int* pa=&a, *pb=&b, *pc=&c;
Pointer pa points at box a. &a is just an address in memory.
Pointer pb points at box b. Pointer pc points at box c.

First assigmed happens with a
a=b*c;
This is just basic algebra

Second assigment is taught one
a*=c;
This has nothing to do with pointers. It is just and syntax niche lika a+=2 or a-=7
At the end this only means a=a*c

Get the real value
b=*pa;
A$$hole * means that the pointer needs the real value of box. It can be easy be mismatched with pointer address.

Now we talk about addreses. What is the address where the pointers is aiming at?
pc=pa;
So if the pointer pa are aiming on duck then tha pointer pc now pointing too.

Pointer pb point at one box and thet box needs to recieve new value
*pb=b*c;

The value of c box depends on boxes where the pointer pa and pc aims
c=(*pa)*(*pc)
The box value where pointer pc aims depends on a multiplication with box where pb aiming at
*pc=a*(*pb);
http://youtu.be/xFxE68JE1T0?t=48m1s

Sunday, October 19, 2014

Log a meow

Friday, October 17, 2014

Sync clock under linux with ntp server

Make sure the ntp package is installed

On debian run
sudo apt-get install ntp
On CentOS, Red Hat run
yum install ntp
Create scheduled synchronization
sudo sh
echo '#!/bin/sh' > /etc/cron.daily/synctime
echo 'ntpdate -u ntp.catonrug.net > /dev/null 2>&1' >> /etc/cron.daily/synctime
chmod 755 /etc/cron.daily/synctime
exit
Sync now
ntpdate -u ntp.catonrug.net > /dev/null 2>&1
Restart cron
/etc/init.d/cron restart
Source:
http://www.howtogeek.com/tips/how-to-sync-your-linux-server-time-with-network-time-servers-ntp/

Tuesday, October 14, 2014

Physical restart Sony Xperia Z1

To restart the device you must shut it down first.
This can be done by opening the slot where SIM card is having a good time.

Use something very thin like pencil or toothpick and hold down the off button for three seconds ;)

Sunday, October 12, 2014

Cat family

Friday, October 10, 2014

Output content from log file into zabbix dashboard, regexp example

On the client side create item that looks for specific condition in log file
UserParameter=custom_item,if exist c:\pat\to\output.log cat c:\pat\to\output.log | grep -e "content.*found" | tail -1
To use the last value use tail -1.
To use first value use head -1.

Into zabbix server create item custom_item with text value

Create trigger name
Details from log file {ITEM.LASTVALUE}
Formula
{servername:custom_item.regexp(content)}=1
Do not use quotes inside regex()!
If the log file meets defined condition it will be reported into zabbix dashboard :)

ITEM.LASTVALUE is truncated to 20 characters

1) In zabbix server search for items.inc.php
find / -name *items.inc.php
open file
vi /var/www/html/include/items.inc.php
type / for search and write zbx_strlen or mb_strlen

        // apply value mapping
        switch ($item['value_type']) {
                case ITEM_VALUE_TYPE_STR:
                        $mapping = getMappedValue($value, $item['valuemapid']);
                // break; is not missing here
                case ITEM_VALUE_TYPE_TEXT:
                case ITEM_VALUE_TYPE_LOG:
                        if ($trim && zbx_strlen($value) > 20) {
                                $value = zbx_substr($value, 0, 20).'...';
                        }

                        if ($mapping !== false) {
                                $value = $mapping.' ('.$value.')';
                        }
                        break;
                default:
                        $value = applyValueMap($value, $item['valuemapid']);
        }

        return $value;
Replace with something bigger
        // apply value mapping
        switch ($item['value_type']) {
                case ITEM_VALUE_TYPE_STR:
                        $mapping = getMappedValue($value, $item['valuemapid']);
                // break; is not missing here
                case ITEM_VALUE_TYPE_TEXT:
                case ITEM_VALUE_TYPE_LOG:
                        if ($trim && zbx_strlen($value) > 20) {
                                $value = zbx_substr($value, 0, 40).'...';
                        }

                        if ($mapping !== false) {
                                $value = $mapping.' ('.$value.')';
                        }
                        break;
                default:
                        $value = applyValueMap($value, $item['valuemapid']);
        }

        return $value;
Save file with :wq

Restart zabbix server
service zabbix_server restart
Source:
https://support.zabbix.com/browse/ZBX-4303
http://www.howtogeek.com/112674/how-to-find-files-and-folders-in-linux-using-the-command-line/ https://www.zabbix.com/forum/showthread.php?t=12402

Monday, October 6, 2014

Windows Update error code 80072F78


This happens if you receive a bad internet connection speed. Just wait a few minutes and try again.

You can also try to clean whole windows update cache with
net stop wuauserv
rd %systemroot%\SoftwareDistribution /Q /S
SC sdshow wuauserv
SC sdset wuauserv D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;AU)(A;;CCLCSWRPWPDTLOCRRC;;;PU)
wuauclt.exe /detectnow
Source:
http://windows.microsoft.com/en-us/windows7/windows-update-error-80072f78-80090305-or-8009033f

UserParameter, Permission denied, zabbix

For example you have zabbix_agentd.conf with very simple command
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
DebugLevel=3
EnableRemoteCommands=1
Server=zabbix.catonrug.net
Hostname=another.catonrug.net

UserParameter=count_failed,cat /var/path/to/log.out | grep "failed" | wc -l
At the zabbix server side you have configured item similar to this
When you restart agent
/etc/init.d/zabbix-agent restart
And the /var/log/zabbix/zabbix_agentd.log file after a minute or two says
 13244:20141006:151140.810 Got signal [signal:15(SIGTERM),sender_pid:14078,sender_uid:0,reason:0]. Exiting ...
 13241:20141006:151140.810 Got signal [signal:15(SIGTERM),sender_pid:14078,sender_uid:0,reason:0]. Exiting ...
 13246:20141006:151140.810 Got signal [signal:15(SIGTERM),sender_pid:14078,sender_uid:0,reason:0]. Exiting ...
 13243:20141006:151140.811 Got signal [signal:15(SIGTERM),sender_pid:14078,sender_uid:0,reason:0]. Exiting ...
 13245:20141006:151140.818 Got signal [signal:15(SIGTERM),sender_pid:14078,sender_uid:0,reason:0]. Exiting ...
 13241:20141006:151142.810 Zabbix Agent stopped. Zabbix 2.0.10 (revision 40809).
 14091:20141006:151142.939 Starting Zabbix Agent [another.catonrug.net]. Zabbix 2.0.10 (revision 40809).
 14093:20141006:151142.940 agent #0 started [collector]
 14094:20141006:151142.941 agent #1 started [listener]
 14095:20141006:151142.941 agent #2 started [listener]
 14096:20141006:151142.941 agent #3 started [listener]
cat: /var/path/to/log.out: Permission denied
Check the current SELinux policy status
This will give output similat to:
SELinux status:                 enabled
SELinuxfs mount:                /selinux
Current mode:                   enforcing
Mode from config file:          permissive
Policy version:                 24
Policy from config file:        targeted
Try out to turn of SELinux policy with
setenforce 0
Now check again status
SELinux status:                 enabled
SELinuxfs mount:                /selinux
Current mode:                   permissive
Mode from config file:          permissive
Policy version:                 24
Policy from config file:        targeted
Now restart zabbix agent
/etc/init.d/zabbix-agent restart
Check the log
tail -f /var/log/zabbix/zabbix_agentd.log
Related:
http://www.linuxcommand.org/man_pages/setenforce8.html

Sunday, October 5, 2014

Wednesday, October 1, 2014

Install cs50.h library on Wheezy Raspbian

move to include direcotry
cd /usr/include
copy this content to clipboard
/****************************************************************************
 * CS50 Library 6
 * https://manual.cs50.net/library/
 *
 * Based on Eric Roberts' genlib.c and simpio.c.
 *
 * Copyright (c) 2013,
 * Glenn Holloway <holloway@eecs.harvard.edu>
 * David J. Malan <malan@harvard.edu>
 * All rights reserved.
 *
 * BSD 3-Clause License
 * http://www.opensource.org/licenses/BSD-3-Clause
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 * * Redistributions of source code must retain the above copyright notice,
 *   this list of conditions and the following disclaimer.
 * * Redistributions in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in the
 *   documentation and/or other materials provided with the distribution.
 * * Neither the name of CS50 nor the names of its contributors may be used
 *   to endorse or promote products derived from this software without
 *   specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ***************************************************************************/

#ifndef _CS50_H
#define _CS50_H

#include <float.h>
#include <limits.h>
#include <stdbool.h>
#include <stdlib.h>

/**
 * Our own data type for string variables.
 */
typedef char* string;

/**
 * Reads a line of text from standard input and returns the equivalent
 * char; if text does not represent a char, user is prompted to retry.
 * Leading and trailing whitespace is ignored.  If line can't be read,
 * returns CHAR_MAX.
 */
char GetChar(void);

/**
 * Reads a line of text from standard input and returns the equivalent
 * double as precisely as possible; if text does not represent a
 * double, user is prompted to retry.  Leading and trailing whitespace
 * is ignored.  For simplicity, overflow and underflow are not detected.
 * If line can't be read, returns DBL_MAX.
 */
double GetDouble(void);

/**
 * Reads a line of text from standard input and returns the equivalent
 * float as precisely as possible; if text does not represent a float,
 * user is prompted to retry.  Leading and trailing whitespace is ignored.
 * For simplicity, overflow and underflow are not detected.  If line can't
 * be read, returns FLT_MAX.
 */
float GetFloat(void);

/**
 * Reads a line of text from standard input and returns it as an
 * int in the range of [-2^31 + 1, 2^31 - 2], if possible; if text
 * does not represent such an int, user is prompted to retry.  Leading
 * and trailing whitespace is ignored.  For simplicity, overflow is not
 * detected.  If line can't be read, returns INT_MAX.
 */
int GetInt(void);

/**
 * Reads a line of text from standard input and returns an equivalent
 * long long in the range [-2^63 + 1, 2^63 - 2], if possible; if text
 * does not represent such a long long, user is prompted to retry.
 * Leading and trailing whitespace is ignored.  For simplicity, overflow
 * is not detected.  If line can't be read, returns LLONG_MAX.
 */
long long GetLongLong(void);

/**
 * Reads a line of text from standard input and returns it as a
 * string (char *), sans trailing newline character.  (Ergo, if
 * user inputs only "\n", returns "" not NULL.)  Returns NULL
 * upon error or no input whatsoever (i.e., just EOF).  Leading
 * and trailing whitespace is not ignored.  Stores string on heap
 * (via malloc); memory must be freed by caller to avoid leak.
 */
string GetString(void);

#endif
The content has been extracted from
http://mirror.cs50.net/appliance50/2014/debs/dists/trusty/main/binary-i386/library50-c_6-0_i386.deb

With super user permissions create a new file
sudo nano cs50.h
Now paste all content in clipboard
Press ctrl+x to exit editing
Press y to accept saving
Hit enter to chose the same filename

Compile the file
sudo gcc -c -ggdb -std=c99 cs50.c -o cs50.o
i do not know what this does but it creates libcs50.a from cs50.o
sudo ar rcs libcs50.a cs50.o
Set to the booth of files that only owner can change the content, everyone can read and none can execute
sudo chmod 0644 cs50.h libcs50.a
move the library to /usr/lib
sudo mv libcs50.a ../lib
Source:
http://askubuntu.com/questions/111744/how-to-install-custom-c-library

Related:
http://cs50.tv/2014/fall/

Compile c code in wheezy raspbian

To compile c code install clang library
sudo apt-get clang -y
Once you have done you can compile with
clang -o filename source.c
example code
#include 
int main(void) {
printf ("How you doing?\n");
}
Related:
http://cs50.tv/2014/fall/