2013年12月28日 星期六

Nagios notify by gmail

# cd /usr/lib/nagios/plugins
# wget  http://exchange.nagios.org/components/com_mtree/attachment.php?link_id=3489&cf_id=24 -O  send_gmail.py
# vi send_gmail.py
# change to your username and password
# vi /etc/nagios3/conf.d/contacts_nagios2.cfg
define contact{
        contact_name                    root
        alias                           Root
        service_notification_period     24x7
        host_notification_period        24x7
        service_notification_options    w,u,c,r
        host_notification_options       d,r
        service_notification_commands   notify-service-by-email
        host_notification_commands      notify-host-by-email
       email                           YOUR_EMAIL_ADDRESS
# vi /etc/nagios3/commands.cfg
# comment old 'notify-host-by-email' and 'notify-service-by-email' command line and add follows
# *)notify-host-by-email

command_line /usr/bin/python /usr/lib/nagios/plugins/send_gmail.py -a $CONTACTEMAIL$ -b "***** Nagios *****\nnn\nnnNotification Type: $NOTIFICATIONTYPE$\nnnHost: $HOSTNAME$\nnnState: $HOSTSTATE$\nnnAddress: $HOSTADDRESS$\nnnInfo: $HOSTOUTPUT$\nnnDate/Time: $LONGDATETIME$" -s "** Nagios $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **"

#notify-service-by-email

command_line /usr/bin/python /usr/lib/nagios/plugins/send_gmail.py -a $CONTACTEMAIL$ -b "***** Nagios *****\nnn\nnnNotification Type: $NOTIFICATIONTYPE$\nnnService: $SERVICEDESC$\nnnHost: $HOSTALIAS$\nnnAddress: $HOSTADDRESS$\nnnState: $SERVICESTATE$\nnnDate/Time: $LONGDATETIME$\nnnAdditional Info: $SERVICEOUTPUT$" -s "** Nagios $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" 



References :
Nagios Alerts via gmail and python - Nagios Exchange
4 Steps to Define Nagios Contacts With Email and Pager Notification

2013年12月25日 星期三

Check Linux kernel bit version

$ uname -m




References :
HowTo: Find Out My Linux Distribution Name and Version

Fluentd regexp example and Fluentular



References :
tail Input Plugin | Fluentd
Fluentular: a Fluentd regular expression editor

Fluentd 區分不同主機來源 Fluentd add hostname in data

1.
Use tag name
Collecting Logs into Elasticsearch and S3 | Fluentd

<source>
  type tail
  format apache
  path /var/log/httpd/access_log
  pos_file /var/log/td-agent/httpd.access.pos
  tag hostname.httpd.access
</source>

<match *.*>
  type elasticsearch
  host localhost
  port 9200
  include_tag_key true
  tag_key @log_name
  logstash_format true
  flush_interval 10s
</match>

2.
fukata/fluent-plugin-hostname


<source>
    type syslog
    port 5140
    bind 0.0.0.0
    format /^(?

</source>

<match system.**>
  type hostname
  key_name @source_host
  add_prefix es

</match>

<match es.system.**>
  type elasticsearch
  logstash_format true
  host 192.168.1.253
  port 9200
  index_name fluentd
  type_name syslog
  flush_interval 1s
  include_tag_key true
  tag_key @log_name
</match>


3.
repeatedly/fluent-plugin-record-modifier

checking for GeoIP_record_by_ipnum() in -lGeoIP... no

apt-get install libgeoip-dev

2013年12月24日 星期二

Fluentd error="Unknown output plugin 'geoip'.

# gem install fluent-plugin-geoip

Exception in thread "main" java.lang.UnsupportedClassVersionError: : Unsupported major.minor version 51.0

Java Version    Major Version
Java 4          48.0
Java 5          49.0
java 6          50.0
java 7          51.0




References :
How to fix java.lang.unsupportedclassversionerror unsupported major.minor version 49.0 50.0 51.0 in Java | Java67

Linux LanguageTool Style and Grammar Checker

LanguageTool Style and Grammar Checker

$ wget  http://languagetool.org/download/LanguageTool-2.3.zip

// To use the simple demo GUI
$ java -jar languagetool-standalone.jar'

// To check plain text files from the command line
$ java -jar languagetool-commandline.jar

Windows 7 enable Aministrator account

> net user administrator /active:yes




References :
Enable the (Hidden) Administrator Account on Windows 7 or Vista

fluentd 手動安裝

# wget http://packages.treasure-data.com/debian/pool/contrib/t/td-agent/td-agent_1.1.18.orig.tar.gz
# tar zxf td-agent_1.1.18.orig.tar.gz
# cd td-agent-1.1.18

# git clone https://github.com/fluent/fluentd.git
# cd fluentd

# apt-get update
# apt-get install ruby ruby1.9.1-dev
# gem install yajl-ruby msgpack cool.io http_parser
# gem install fluent-plugin-elasticsearch fluent-plugin-hostname

# vi fluent.conf
# ./bin/fluentd -c fluent.conf -vv &




References :
Installing Fluentd from Source | Fluentd

[error]: config error file="fluent.conf" error="Unknown output plugin 'elasticsearch'.

[error]: config error file="fluent.conf" error="Unknown output plugin 'elasticsearch'. Run 'gem search -rd fluent-plugin' to find plugins"


# gem install  fluent-plugin-elasticsearch

`require': cannot load such file -- http/parser

# gem install http_parser

`require': cannot load such file -- cool.io (LoadError)

# gem install cool.io

2013年12月23日 星期一

2013年12月22日 星期日

Install ElasticSearch-head web front end

# /usr/share/elasticsearch/bin/plugin -install mobz/elasticsearch-head

http://localhost:9200/_plugin/head/





References :
mobz/elasticsearch-head

rsyslog 設定

Server 設定:
1. 設定監聽 port
2. 設定 log template
Linux Log Server 教學




Client 設定:
# vi /etc/rsyslog.conf

*.* @192.168.6.254:514  # 指定所有 log
mail.warn @192.168.6.254:514  # 指定特定 log

2013年12月17日 星期二

Miller Puckette 來臺灣

時間:12/16 (一) 19:00~21:00
地點:睡不著咖啡(地下室)

http://www.facebook.com/groups/286242531394736/permalink/706923579326627/





今天有聽到一些討論:


臺灣社羣爲 Pd 做了一個 extension,一個 Toolbar,方便可以新增物件。


Q : 爲什麼會使用 Tcl/Tk 做 GUI 介面?
A : 在 1990 年代就是用 Tcl/Tk,而且它能運作。或許可以用 parser 將 pd 物件專成在 GTK+ 上顯示。

    一些相關討論:



Pure Data 中文輸入問題:

    2011/3/31 Puredata.Taipei: puredata 0.43發布

   在 Pure Data 0.43 發布後,可輸入中文,但是中文字會超過物件外框 (Bug),由 Kanru 發布的 Patch 修正。至今,Pure Data 在 Linux 下中文輸入還是有點問題,輸入法切換鍵可能被佔用,目前可用的有 Fcitx 輸入法,ibus、gcin 不行。
  

alsa/asoundlib.h no such file or directory

# apt-get install libasound2-dev





References :
linux - Alsa Headers not found in Ubuntu 9.04 - Super User

2013年12月15日 星期日

prrtty print json format string in command line

$ echo '{"a":1, "b":2}' | python -m json.tool




References :
Best Way To Pretty Print (Format) JSON On The Command-Line

list all ElasticSearch indexes

$ curl localhost:9200/_stats | python -m json.tool

$ curl localhost:9200/index1,index2/_stats | python -m json.tool




References :
Indices Stats

`require': cannot load such file -- msgpack

# gem install msgpack

cannot load such file -- yajl (LoadError)

# gem install yajl-ruby




References :
ruby on rails - LoadError on require yajl - Stack Overflow

The compiler failed to generate an executable file. (RuntimeError) You have to install development tools first.

# apt-get install build-essential




References :
deployment - error on installing passenger nginx module on ubuntu with ruby 2.0.0 via rvm - Stack Overflow

`require': no such file to load — mkmf (LoadError)

# apt-get install ruby1.9.1-dev




References :
ruby on rails - `require': no such file to load -- mkmf (LoadError) - Stack Overflow

play midi file on linux

timidity - Software sound renderer (MIDI sequencer, MOD player)




References :
Midi/SoftwareSynthesisHowTo - Community Ubuntu Documentation

python play midi file using pygame




References :
Play a Midi Music File using PyGame | DaniWeb

2013年12月13日 星期五

Apache rewrite module with POST parameters

httpd.conf
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule rewrite_module modules/mod_rewrite.so

RewriteEngine On
RewriteRule project/(index.php.*) http://192.168.1.2/project/%1 [R=301,P]
 



References :
为Apache rewrite转发添加POST数据支持Alex's blog | Alex's blog
HTTP POST请求的Apache Rewrite规则设置 - slvher的专栏 - 博客频道 - CSDN.NET

2013年12月11日 星期三

Parse error: syntax error, unexpected '['

PHP 5.3:
$year = explode("-", "2013-12-12")[0];
$year = $year[0];

PHP 5.5:
$year = explode("-", "2013-12-12")[0];

Linux extracting PDF images

pdfimages -j xxx.pdf /tmp/out
 
 
 
 
References :
software recommendation - Extracting images from a PDF - Ask Ubuntu 

Linux PDF to text

pdftotext [options] []

-layout           : maintain original physical layout

2013年12月10日 星期二

MySQL Replication

MySQL 5.1 版適用

References :
The Will Will Web | 如何在 MySQL 5.5 設定單向資料庫複寫機制 (Replication)

CentOS install Apache PHP MySQL



References :
Installing Apache2 With PHP5 And MySQL Support On CentOS 6.2 (LAMP) | HowtoForge - Linux Howtos and Tutorials

yum list installed packages

$ yum list installed




References :
List installed packages with YUM

Warning: date(): It is not safe to rely on the system's timezone settings.

Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier.

 
修正方法:2 種

1. 在 php.ini 裏設定 date.timezone
date_default_timezone_set('Asia/Taipei');
2. 在程式碼裏使用 date_default_timezone_set() 函式
date.timezone = "Asia/Taipei"


Debian :
# vi /etc/php5/apache2/php.ini
CentOS :
# vi /etc/php.ini




References :
PHP 5.3.x 的 strtotime() 時區設定 警告訊息修正 - Tsung's Blog

0xC004C020

通常發生於使用零售版(或OEM版)作業系統試圖進行KMS認證,或者於安裝作業系統後曾經使用MAK序號,或安裝完後未進行認證導致。

slmgr /dlv
slmgr /ipk 33PXH-7Y6KF-2VJC9-XBBR8-HVTHH


References :
微軟授權下載認證服務 - Windows
Appendix A: KMS Client Setup Keys

2013年12月9日 星期一

CentOS firewall config

# vi /etc/sysconfig/iptables
# HTTP
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

# NFS
-A INPUT -m state --state NEW -m udp -p udp --dport 2049 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 2049 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 111 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 111 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 32769 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 32803 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 892 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 892 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 875 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 875 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 662 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 662 -j ACCEPT

# Samba
-A INPUT -m state --state NEW -m udp -p udp --dport 137 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 138 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 139 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 445 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 445 -j ACCEPT
# /etc/init.d/iptables restart




References:
CentOS / Redhat Iptables Firewall Configuration Tutorial

Raspbian 預設帳號密碼

Username: pi
Password: raspberry




Reference :
Raspberry Pi Beginners Guide - neil-black.co.uk

2013年12月6日 星期五

javscript json encdoe & decode

> var arr = { };
undefined
> arr['aa'] = 111;
111
> arr['bb'] = 222;
222
> arr
{ aa: 111, bb: 222 }
> var json = JSON.stringify(arr);  // dictionary to json string
undefined
> typeof(json);
'string'
> json
'{"aa":111,"bb":222}'
> JSON.parse(json);  // json decode
{ aa: 111, bb: 222 }





Reference :
Encoding Javascript Object to Json string - Stack Overflow
How to parse JSON in JavaScript - Stack Overflow