Saturday, 21 December 2013

Tools and web to studing ASP.NET

I have learnt ASP.NET recently, and will share some information in this article.

Tools/IDE

First, tools for coding ASP.NET. ASP.NET is Microsoft 's product so you must use Windows to code and tools are run in Windows. There are three tools (all are of Microsoft):

Webmatrix

Homepage: http://www.microsoft.com/web/webmatrix/
A free, easy to use tools, match for newbie. Many tutorials in learning asp.net websites base on this tool.
Some characteristics:
  • Small, easy to install, easy to install extension.
  • Simple to use.
  • Support autocomplete (with overloading methods are not good), highlight code.
  • Support PHP, ASP classic
  • Don't support debug, format code ...
Webmatrix tientuts


Microsoft Visual Studio Express for Web

An advanced tool with many features, and acquainted with dotnet developer . I think will this, you can use normal demands.


Microsoft Visual Studio paid versions

Same Express but with functions for business. With me, Express version is enough but when you work in company, and need more, you can use paid versions.


Web to learn ASP.NET

http://www.asp.net/ go to learn tab and read

http://www.microsoft.com/web/category/all  other of microsoft

http://www.w3schools.com/aspnet a famous website for learning web.

Saturday, 16 November 2013

Debug php with Netbeans and Xampp

Xampp is one of the best free tool for develop website in localhost.
With Xampp I can use php with Apache module, database with MySQL, transfer file with FileZilla, web java ee with Tomcat. And it is very easy to install, only download from here and install, open and click start modules.

Netbeans is still one of the best free IDE to develop many language (java, c++, php ... )

But if you only install netbeans and run Xampp to code php, you will only run to view result, you will not debug: run, pause, step lines and view changed variables...


Today, I will present how to debug php with Netbeans and Xampp because Xampp was integrated xdebug and easy to config when compare with others way.

I use Netbeans 7.4 and Xampp 3.1.0.

XAMPP
Config php.ini in XDebug area.

[XDebug]
zend_extension = "E:\xampp\php\ext\php_xdebug.dll"
xdebug.remote_enable=1
xdebug.remote_handler="dbgp"
xdebug.remote_mode=req
xdebug.remote_port=9000

xdebug.profiler_append = 0
xdebug.profiler_enable = 1
xdebug.profiler_enable_trigger = 0
xdebug.profiler_output_dir = "E:\xampp\tmp"
xdebug.profiler_output_name = "cachegrind.out.%t-%s"
xdebug.remote_host = "127.0.0.1"
xdebug.trace_output_dir = "E:\xampp\tmp"

tientuts blogger


Netbeans

Go to menu: Tools -> Options and config like this image


And restart Netbeans, Xampp to active debug

Sunday, 10 November 2013

Install psycopg2 with Postgresql

psycopg2 is a driver in python to connect python application with postgresql.

Install library in python, normal is easy with pip, easy_install but with psycopg2, I met errors in all linux and window.

With window, I can use this option:
http://tientuts.blogspot.com/2013/10/fix-some-errors-when-install-library.html

but with linux, when I install, this is a very common error:

Error: pg_config executable not found.

Please add the directory containing pg_config to the PATH

or specify the full executable path with the option:



    python setup.py build_ext --pg-config /path/to/pg_config build ...



or with the pg_config option in 'setup.cfg'.

----------------------------------------
Command python setup.py egg_info failed with error code 1 in /tmp/pip-build/psycopg2


After search google and try, this is my solution (in Centos):
Install postgresql in here: https://wiki.postgresql.org/wiki/Detailed_installation_guides
In present, the newest version of postgresql is 9.3 and we need setup PATH value for postgresql

PATH=$PATH:/usr/pgsql-9.3/bin/
pip install psycopg2


Saturday, 2 November 2013

Multitask in the Linux Terminal

The oldest operating system I have ever studied is MS-DOS. This is a single tasking operating system, in the easiest way, you can see DOS like a single command line (cmd) window. In a long time, I use DOS single tasking and in the habit, I use cmd only in a single window. And when I use Linux with terminal (more power than cmd in window), the first time, I still use one terminal window, single tasking. But because of job requirements and the convenience of multitask, I changed, have use terminal with multi-task function (in many window/tab or in single window) or can be called: Multiple screen/area.


Multiple window and mutiple tab
With linux GUI (graphic user interface), these are the easiest ways.

Multiple window and multiple tab in terminal


With many terminals, you can easy change folder, run many terminal progresses like install a software and download a file and edit a text simultaneously.


Virtual consoles

Multiple window and mutiple tab are easy but What you do if you control a Ubuntu server without GUI ?

Linux has a function for this, this is virtual consoles, you can do with 6 terminals by use:
Ctrl+Alt+F1
for the first console, Ctrl+Alt+F2 -> F6 for other,  Ctrl+Alt+F7 for return graph (if GUI is installed).


Multitask with screen command

Virtual consoles is good function but if you telnet/ssh from pc to a server with putty, cmd or other, you can't use Ctrl+Alt+F<1-6>. You can do with many window by retype connect commands and password, so slow, and you can use screen command to multitask terminals.

Install (in ubuntu/debian):

sudo apt-get install screen

Some basic command to use

Create a screen:
screen -S name
Exit/detache screen:
ctrl+A, D
Go to an  existed screen
screen -r name
Terminal a screen:
ctrl+A, K


Other way

use a software can auto connect and auto fill password like Multi-Tabbed PuTTY, secure crt ..

Multi-Tabbed PuTTY tientus blogger



Tuesday, 29 October 2013

Fix some errors when install library Python in Window

When you install some library in pip/easy_install like pycrypto or library need pycrypto like paramiko, virtualenv ...
Always I meet this stupid error:

Unable to find vcvarsall.bat
Search google, I find some solutions like install visual studio, mingw32 ... because pip or easy_install  will download source code of library and need compiler to compile library.

Above solutions are good, but need many memory to install visual studio, mingw32 and many time to config.

Today, I will introduce a very simple way: this is install compiled library.
Search google with "pycrypto windows 2.7 setup"
We can find "Prebuilt Python Binaries for Windows"
http://www.voidspace.org.uk/python/modules.shtml

Install and use, really easy !!!

Thursday, 17 October 2013

Useful MySQL commands

In window, I often use xampp to run apache and mysql, it has been integrated phpmyadmin and very easy to use with web interface. In linux, installing mysql is very easy but when i install phpmyadmin, almost i must config and search google very much, so I think i need learn some commands to use direct MySQL from terminal.

First we need install mysql, we can install from repo (so easy). And after, run mysql daemon and set password for root user:

/etc/init.d/mysqld start
mysqladmin -u root password {password}

Login to mysql

mysql -h hostname -u root -p

And now, we can use mysql with behind mysql commands.

This is a list of useful MySQL commands. Source from here

Short List of MySQL Commands

Conventions used here:

  • MySQL key words are shown in CAPS
  • User-specified names are in small letters
  • Optional items are enclosed in square brackets [ ]
  • Items in parentheses must appear in the command, along with the parentheses
  • Items that can be repeated as often as desired are indicated by an ellipsis ...

Quoting in MySQL statments

  • Don't quote database, table, or column names
  • Don't quote column types or modifiers
  • Don't quote numerical values
  • Quote (single or double) non-numeric values
  • Quote file names and passwords
  • User names are NOT quoted in GRANT or REVOKE statements, but they are quoted in other statements.


General Commands
USE database_name
     Change to this database. You need to change to some database when you first connect to MySQL.
SHOW DATABASES
     Lists all MySQL databases on the system.
SHOW TABLES [FROM database_name]
     Lists all tables from the current database or from the database given in the command.
DESCRIBE table_name
SHOW FIELDS FROM table_name
SHOW COLUMNS FROM table_name
     These commands all give a list of all columns (fields) from the given table, along with column type and other info.
SHOW INDEX FROM table_name
     Lists all indexes from this tables.
SET PASSWORD=PASSWORD('new_password')
     Allows the user to set his/her own password.
Table Commands
CREATE TABLE table_name (create_clause1, create_clause2, ...)
     Creates a table with columns as indicated in the create clauses.
     create_clause
     column name followed by column type, followed optionally by modifiers. For example, "gene_id INT AUTO_INCREMENT PRIMARY KEY" (without the quotes) creates a column of type integer with the modifiers described below.
     create_clause modifiers
     
  • AUTO_INCREMENT : each data record is assigned the next sequential number when it is given a NULL value.
  • PRIMARY KEY : Items in this column have unique names, and the table is indexed automatically based on this column. One column must be the PRIMARY KEY, and only one column may be the PRIMARY KEY. This column should also be NOT NULL.
  • NOT NULL : No NULL values are allowed in this column: a NULL generates an error message as the data is inserted into the table.
  • DEFAULT value : If a NULL value is used in the data for this column, the default value is entered instead.
DROP TABLE table_name
     Removes the table from the database. Permanently! So be careful with this command!
ALTER TABLE table_name ADD (create_clause1, create_clause2, ...)
     Adds the listed columns to the table.
ALTER TABLE table_name DROP column_name
     Drops the listed columns from the table.
ALTER TABLE table_name MODIFY create_clause
     Changes the type or modifiers to a column. Using MODIFY means that the column keeps the same name even though its type is altered. MySQL attempts to convert the data to match the new type: this can cause problems.
ALTER TABLE table_name CHANGE column_name create_clause
     Changes the name and type or modifiers of a column. Using CHANGE (instead of MODIFY) implies that the column is getting a new name.
ALTER TABLE table_name ADD INDEX [index_name] (column_name1, column_name2, ...)
CREATE INDEX index_name ON table_name (column_name1, column_name2, ...)
     Adds an index to this table, based on the listed columns. Note that the order of the columns is important, because additional indexes are created from all subsets of the listed columns reading from left to write. The index name is optional if you use ALTER TABLE, but it is necesary if you use CREATE INDEX. Rarely is the name of an index useful (in my experience).
Data Commands
INSERT [INTO] table_name VALUES (value1, value2, ...)
     Insert a complete row of data, giving a value (or NULL) for every column in the proper order.
INSERT [INTO] table_name (column_name1, column_name2, ...) VALUES (value1, value2, ...)
INSERT [INTO] table_name SET column_name1=value1, column_name2=value2, ...
     Insert data into the listed columns only. Alternate forms, with the SET form showing column assignments more explicitly.
INSERT [INTO] table_name (column_name1, column_name2, ...) SELECT list_of_fields_from_another_table FROM other_table_name WHERE where_clause
     Inserts the data resulting from a SELECT statement into the listed columns. Be sure the number of items taken from the old table match the number of columns they are put into!
DELETE FROM table_name WHERE where_clause
     Delete rows that meet the conditions of the where_clause. If the WHERE statement is omitted, the table is emptied, although its structure remains intact.
UPDATE table_name SET column_name1=value1, column_name2=value2, ... [WHERE where_clause]
     Alters the data within a column based on the conditions in the where_clause.
LOAD DATA LOCAL INFILE 'path to external file' INTO TABLE table_name
     Loads data from the listed file into the table. The default assumption is that fields in the file are separated by tabs, and each data record is separated from the others by a newline. It also assumes that nothing is quoted: quote marks are considered to be part of the data. Also, it assumes that the number of data fields matches the number of table columns. Columns that are AUTO_INCREMENT should have NULL as their value in the file.
LOAD DATA LOCAL INFILE 'path to external file' [FIELDS TERMINATED BY 'termination_character'] [FIELDS ENCLOSED BY 'quoting character'] [LINES TERMINATED BY 'line termination character'] FROM table_name
     Loads data from the listed file into the table, using the field termination character listed (default is tab \t), and/or the listed quoting character (default is nothing), and/or the listed line termination chacracter (default is a newline \n).
SELECT column_name1, column_name2, ... INTO OUTFILE 'path to external file' [FIELDS TERMINATED BY 'termination_character'] [FIELDS ENCLOSED BY 'quoting character'] [LINES TERMINATED BY 'line termination character'] FROM table_name [WHERE where_clause]
     Allows you to move data from a table into an external file. The field and line termination clauses are the same as for LOAD above. Several tricky features:
  1. Note the positions of the table_name and where_clause, after the external file is given.
  2. You must use a complete path, not just a file name. Otherwise MySQL attempts to write to the directory where the database is stored, where you don't have permission to write.
  3. The user who is writing the file is 'mysql', not you! This means that user 'mysql' needs permission to write to the directory you specify. The best way to do that is to creat a new directory under your home directory, then change the directory's permission to 777, then write to it. For example: mkdir mysql_output, chmod 777 mysql_output.

Privilege Commands
Most of the commands below require MySQL root access
GRANT USAGE ON *.* TO user_name@localhost [IDENTIFIED BY 'password']
     Creates a new user on MySQL, with no rights to do anything. The IDENTIFED BY clause creates or changes the MySQL password, which is not necessarily the same as the user's system password. The @localhost after the user name allows usage on the local system, which is usually what we do; leaving this off allows the user to access the database from another system. User name NOT in quotes.
GRANT SELECT ON *.* TO user_name@localhost
     In general, unless data is supposed to be kept private, all users should be able to view it. A debatable point, and most databases will only grant SELECT privileges on particular databases. There is no way to grant privileges on all databses EXCEPT specifically enumerated ones.
GRANT ALL ON database_name.* TO user_name@localhost
     Grants permissions on all tables for a specific database (database_name.*) to a user. Permissions are for: ALTER, CREATE, DELETE, DROP, INDEX, INSERT, SELECT, UPDATE.
FLUSH PRIVILEGES
     Needed to get updated privileges to work immediately. You need RELOAD privileges to get this to work.
SET PASSWORD=PASSWORD('new_password')
     Allows the user to set his/her own password.
REVOKE ALL ON [database_name.]* FROM user_name@localhost
     Revokes all permissions for the user, but leaves the user in the MySQL database. This can be done for all databases using "ON *", or for all tables within a specific databse, using "ON database_name.*".
DELETE FROM mysql.user WHERE user='user_name@localhost'
     Removes the user from the database, which revokes all privileges. Note that the user name is in quotes here.
UPDATE mysql.user SET password=PASSWORD('my_password') WHERE user='user_name'
     Sets the user's password. The PASSWORD function encrypts it; otherwise it will be in plain text.
SELECT user, host, password, select_priv, insert_priv, shutdown_priv, grant_priv FROM mysql.user
     A good view of all users and their approximate privileges. If there is a password, it will by an encrytped string; if not, this field is blank. Select is a very general privlege; insert allows table manipulation within a database; shutdown allows major system changes, and should only be usable by root; the ability to grant permissions is separate from the others.
SELECT user, host, db, select_priv, insert_priv, grant_priv FROM mysql.db
     View permissions for individual databases.

Monday, 30 September 2013

SSH Without Password ON RedHat 6/CentOS 6

SSH without password is easy:

Step 1

First log in on A pc and generate a pair of authentication keys. Do not enter a passphrase:

ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/a/.ssh/id_rsa):
Created directory '/home/a/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/a/.ssh/id_rsa.
Your public key has been saved in /home/a/.ssh/id_rsa.pub.
The key fingerprint is:
...


Step 2

Copy authen file to remote host (host B)

ssh-copy-id -i .ssh/id_dsa.pub {hostB_ip/hostB_name}
 

Step 3

From nowyou can log into B as b from A as a without password:

a@A:~> ssh b@{hostB_ip/hostB_name}



Note :
Must Disable Security-Enhanced Linux


If still errors

Change the permissions of .ssh to 700
Change the permissions of .ssh/authorized_keys to 600

Disable Security-Enhanced Linux

Security-Enhanced Linux (SELinux) is a Linux kernel security module that provides the mechanism for supporting access control security policies, including United States Department of Defense-style mandatory access controls (MAC).

In Fedora/Centos, SELinux is not useful and  make some softwares, services can't run. So we need disable it.

There are two way:

Temporary
setenforce 0

Forever
Edit vi /etc/selinux/config and reboot:
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#       enforcing - SELinux security policy is enforced.
#       permissive - SELinux prints warnings instead of enforcing.
#       disabled - SELinux is fully disabled.
SELINUX=disabled
# SELINUXTYPE= type of policy in use. Possible values are:
#       targeted - Only targeted network daemons are protected.
#       strict - Full SELinux protection.
# SELINUXTYPE=targeted



Saturday, 28 September 2013

Fix error can't connect internet when cloning Centos in Virtualbox

When working, I need some test with two Centos virtual machine/pc (6.4 minimal). 
So I installed one virtual machine and clone to another.
And to make two virtual machine can connect one Lan network (or one wifi network) with bridged adapter mode in Network settings, I need check to "Reinitialize the MAC address of all network cards) like behind image.


And when I started new virtual machine, I can't connect to internet.

Solution
 Need go to superuser with su command line


  1. Remove the kernel’s networking interface rules file to reset
    # rm -f /etc/udev/rules.d/70-persistent-net.rules
  1. Restart the VM
# reboot
  1. UPDATE your interface configuration file

    # vi /etc/sysconfig/network-scripts/devices/ifcfg-eth0
  1. Remove the MACADDR entry and the UUID entry
  2. Save and exit the file (:wq)
  3. Restart the networking service
# service network restart
 


Thursday, 26 September 2013

Opsview, a good monitor system base on Nagios

After studying Nagios a period of time, I met Opsview and really like it and want to share it for every body by post an article to this blog.

What is Opsview?
Opsview like Nagios with useful plugins with a nice web interface and easy to config and install.
Nagios is a powerful monitor system but Nagios Core (free) has a basic web interface, almost to read only, to config hosts or options, we need write to files an reload service, database base on text format. Nagios core can't do any think if it stand alone, we must install plugin for check, graph (pnp4nagios, nagiosgraph...) for show status display graphs ... And really hard for install, studying and training newbies.
Opsview Core free.

What can Opview do ?
Opsview is built with the following technologies:
  • Nagios Core: Provides the core set of monitoring and alerting capabilities in Opsview. Sometimes referred to as Opsview's monitoring engine. Many plugin in Nagios is compatible with Opsview
  • Nice web interface: comfortable, easy to use, easy to remember, easy to learn and traning
  • MySQL: A relational database used for configuration, runtime and data warehouse databases
  • RRDtool: Provides lightweight graphing
  • More extend agent
  •  ...
Homepage: http://opsview.com/

Saturday, 21 September 2013

Snapshot function in Virtualbox (backup many status of os)

Virtualbox is a free, opensource virtual pc software. Beside Virtualbox, we can use many other free softwares like qemu, vmware player ... but i think virtualbox is the best because it is nice, power, can connect with gns3 to simulate network systems (qemu can still connect but not power like virtualbox).
In the simplest way, we use Virtual pc software with an iso image file of an operating system to install and run the operating system (OS) in a window to test or run certain tools that the operating system on pc / laptop does not currently do. But virtual pc softwares have many more powerful functions than it and Snapshot is one.
With a real pc/laptop, I use softwares like norton ghost, true image ... to backup OS. I must restart PC with a boot pc and configure to backup to an image file. I need about near half of hour for each time.
With virtualbox, before, I can backup file vdi by compress this to a archive file. I really happy with each time, I only need back in less than ten minutes.
But, with snapshot, I can do them with < one minutes, can backup in running, save memory, and can struct in a tree to manager snapshots.




To use it, we need click snapshot button (blue arrow)
Create snapshot (red arrow), we can do it when virtual pc is running.
And can clone this state to other virtual pc with button in black arror.
Choose status you want to restore, and click restore button near create button.

Very easy,  very powerful. When i try softwares, special in linux (hard to install softwares), this function help me very good.

Friday, 13 September 2013

Scapy, a power network tool for Python

When working, I must meet some project with create pakage, pppoe, ping, catch, filter, authentication ... And I was introduced to learn to use scapy.
Scapy is a power opensource library/app for python.


Homepage: http://www.secdev.org/projects/scapy/

First project I met is pppoe with pap/chap authentication to connect to some bras, server and Scapy support it with automata (advanced function of scapy).

You can see here to know pppoe:

And this is a code

Chap authen


and we can use scapy with other protocols. At the present, I am not sure about Scapy, so you can go to http://networkingbodges.blogspot.com or homepage of scapy to get more information.

Friday, 30 August 2013

Create a simple Nagios plugin support graph (passive check)

First, to know this article, please read and practice active check in here.

Config passive check
Config with nagios core:
vi /usr/local/nagios/etc/nagios.cfg
accept_passive_service_checks option is set to 1 as well.



Manual passive check

Create a plugin like active check article but in define service add two lines:
active_checks_enabled 0
passive_checks_enabled 1


Restart nagios:
sudo -s
service nagios restart
This is the result:

 Click Submit passive check and fill it like this image:

 refresh nagios webpage and wait few seconds and view Status information:

Other way:
Structure:
[<timestamp>] PROCESS_SERVICE_CHECK_RESULT;<host_name>;<service_description>;<service_status>;<plugin_output>
Example:
sudo -s
CHECK="[`date +%s`] PROCESS_SERVICE_CHECK_RESULT;localhost2;Check cpu;0;Ok from commandline"
echo $CHECK >>/usr/local/nagios/var/rw/nagios.cmd



Passive check from remote host

Nagios server (ip: 192.168.0.221)
Install
sudo -s
apt-get install nsca
Edit nsca config:
vi /etc/nsca.cfg
Content to change (if different), can change password to anythink you like but must match client and server:
command_file=/usr/local/nagios/var/rw/nagios.cmd
password=aloha
decryption_method=1
nsca_group=nagios
nsca_user=nagios
Restart nsca
service nsca restart

Client (ip: 192.168.0.33)
Install:
sudo -s
apt-get install nsca-client
Config:
 vi /etc/send_nsca.cfg
change password and encryption_method like server

Check

echo -en "localhost2\tcheck cpu\t0\tCheck Ok from nsca\n" | send_nsca -c /etc/send_nsca.cfg -H 192.168.0.221
Result Ok, but nagios don't do any think.
1 data packet(s) sent to host successfully.
Debug: 

 vi /usr/local/nagios/var/nagios.log

[1377855543] EXTERNAL COMMAND: PROCESS_SERVICE_CHECK_RESULT;localhost2;check cpu;0;Check111 Ok from nsca
[1377855543] Warning: Passive check result was received for service 'check cpu' on host 'localhost2', but the service could not be found!
and this is the reason:
 echo -en "localhost2\tCheck cpu\t0\tCheck Ok from nsca\n" | send_nsca -c /etc/send_nsca.cfg -H 192.168.0.221
Wait for few seconds and data will be update in nagios.
You can see in active check article to see how to create graph.

Tuesday, 27 August 2013

Create a simple Nagios plugin support graph (active check)

In this article, I will post an example of a Nagios plugin support graph.
First, you must install Nagios core and pnp4nagios (I suggest you install like these article because other ways can make some differences).

This code is written by Python, will make random number and return result. You can do with any language can return the same result.


Create plugin

Code

#!/usr/bin/python
import os, sys, random

random = random.randrange(0, 120)

if random < 50:
        print "OK - %s%% cpu|'cpu'=%s%%" % (random, random)
        sys.exit(0)
elif random < 90 and random >= 50:
        print "WARNING - %s%% cpu|'cpu'=%s%%" % (random, random)
        sys.exit(1)
elif random <= 100 and random >= 90:
        print "CRITICAL - %s%% cpu|'cpu'=%s%%" % (random, random)
        sys.exit(2)
else:
        print "UKNOWN - %s%% cpu|'cpu'=%s%%" % (random, random)
        sys.exit(3)

Example result
OK - 47% cpu|'cpu'=47%


Create file

cd /home/
vi plugin.py  (  paste code in vi editor)

chmod 777 plugin.py

Check result
./plugin.py -> UKNOWN - 111% cpu|'cpu'=111%


Config in Nagios (local)
Create a host with service use our plugin
cd /usr/local/nagios/etc
vi test.cfg
paste this content

define host{
        use                     linux-server,host-pnp         ; Name of host template to use
                                                        ; This host definition will inherit all variables that are defined
                                                        ; in (or inherited by) the linux-server host template definition.
        host_name               localhost2
        alias                   localhost2
        address                 127.0.0.1
        }

define service{
        use                             local-service,service-pnp          ; Name of service template to use
        host_name                       localhost2
        service_description             Check cpu
        check_command                   check_cpu
        }

define command{
        command_name    check_cpu
        command_line    /home/plugin.py
        }

vi /usr/local/nagios/etc/nagios.cfg
and this line
cfg_file=/usr/local/nagios/etc/test.cfg


Check config error and restart
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

service nagios restart


Result
And this is the result:


Click to check cpu:

You can see Status information and Performance Data , this is the result of above red plugin result


Graph will be created from Performance Data with this struct: 'label'=value[UOM];[warn];[crit];[min];[max]

See more here: http://nagiosplug.sourceforge.net/developer-guidelines.html

Wait about half of hour or more, and this is my plugin graph :




Config from remote host, via nrpe:
Install in client (ip: 192.168.0.33)
apt-get install -y python nagios-nrpe-server

Disable nagios3 service
Because I use nagios from source (not nagios3 - dependences of nagios-nrpe-server), so, to disable (to get server lighter), we need:
update-rc.d nagios3 disable (for disable service startup with server)
service nagios3 stop (to stop running service)
update-rc.d nagios3 enable (for enable service startup)

Install and check
client:
create plugin.py at /home/plugin.py like above at client

Config
vi /etc/nagios/nrpe.cfg

add any monitor service or host can get infor at allowed_hosts:
allowed_hosts=127.0.0.1,192.168.0.222
add this plugin command:
command[check_cpu]=/home/plugin.py
Save config file and restart
service nagios-nrpe-server restart 


Install in server (ip: 192.168.0.222)
sudo apt-get install nagios-nrpe-plugin

Check nrpe
/usr/lib/nagios/plugins/check_nrpe -H 192.168.0.33 -c check_cpu
And this is the result:
WARNING - 69% cpu|'cpu'=69%

With this command, you can change command in above local config to check remote host.
In fact, we usually use command like:
/usr/lib/nagios/plugins/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
and check_command like:
check_cpu!check_cpu
 with ip will be replaced in $HOSTADDRESS$ and check_cpu after ! will be replaced in $ARG1$.
Go to document of nagios to view more.

Tuesday, 20 August 2013

Check_MK, one of the best plugin for Nagios

Check_MK is a collection of extensions for the IT-Monitoring-Kernel of Nagios and together with this, and ideally also with PNP4Nagios and NagVis constitutes a complete IT-Monitoring-System. Check_MK is 100% Open-Source and is available under the terms of the GNU GPL.

View homepage to get full information:
http://mathias-kettner.com


First must install nagios: view here

After download and extract from :
http://mathias-kettner.com/check_mk_download.html



Install
Must install libapache2-mod-python first.

Go to extracted folder in terminal.
sudo -s
./setup.sh

Next next next and next.
setup progress will auto detect elements.


setup check_mk

Type y, Enter

Restart nagios and apache2 services
service nagios restart
service apache2 restart


This is the result (image from wiki):



Error when run

When I restart linux, having an error
"Livestatus problem: Cannot connect to  'unix:/usr/local/nagios/var/rw/live': [Errno 111] Connection refused"
This is because pemission, use commands:

chown nagios.nagcmd /usr/local/nagios/var/rw
chmod g+rwx /usr/local/nagios/var/rw
chmod g+s /usr/local/nagios/var/rw

Install graph plugin for Nagios (pnp4nagios)

This article will install pnp4nagios plugin for nagios install from source: see here

Go to web, download and extract source code:
http://sourceforge.net/projects/pnp4nagios/


SETUP

Go to superuser mode
sudo -s

install rrdtool and RRDs Perl Modules (dependences for pnp4nagios)
apt-get install libcgi-pm-perl librrds-perl libgd-gd2-perl libnagios-object-perl rrdtool

Download and extract (in present this is the lastest version)
cd ~/downloads (if not exists: mkdir downloads)
wget http://sourceforge.net/projects/pnp4nagios/files/PNP-0.6/pnp4nagios-0.6.21.tar.gz
tar -xzvf pnp4nagios-0.6.21.tar.gz

Compile and Install
cd pnp4nagios-0.6.21/
./configure
make all
make fullinstall

Restart nagios and apache2 services
service nagios restart
service apache2 restart


FIX ERRORS
go to 127.0.0.1/pnp4nagios
and see like this image:

pnp4nagios apache mod rewrite tientuts blog


Fix:
a2enmod rewrite
 /etc/init.d/apache2 restart (like service apache2 restart)
and do like info in below webpage:
Your environment passed all requirements. Remove or rename the /usr/local/pnp4nagios/share/install.php file now.
go to terminal: sudo nautilus -> go to this page and rename file


Config
Still go to terminal: sudo nautilus.

Go to /usr/local/nagios/etc/nagios.cfg,
Change default fields to this content:

process_performance_data=1
host_perfdata_file=/usr/local/pnp4nagios/var/host-perfdata
service_perfdata_file=/usr/local/pnp4nagios/var/service-perfdata
host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA::$HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$\tHOSTOUTPUT::$HOSTOUTPUT$
service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::$SERVICEDESC$\tSERVICEPERFDATA::$SERVICEPERFDATA$\tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$\tSERVICESTATE::$SERVICESTATE$\tSERVICESTATETYPE::$SERVICESTATETYPE$\tSERVICEOUTPUT::$SERVICEOUTPUT$
host_perfdata_file_mode=a
service_perfdata_file_mode=a
host_perfdata_file_processing_interval=15
service_perfdata_file_processing_interval=15
host_perfdata_file_processing_command=process-host-perfdata-file
service_perfdata_file_processing_command=process-service-perfdata-file

Go to /usr/local/nagios/etc/objects/commands.cfg, append the command definitions:
define command {
command_name    process-service-perfdata-file
command_line    /usr/local/pnp4nagios/libexec/process_perfdata.pl --bulk=/usr/local/pnp4nagios/var/service-perfdata
}

define command {
command_name    process-host-perfdata-file
command_line    /usr/local/pnp4nagios/libexec/process_perfdata.pl --bulk=/usr/local/pnp4nagios/var/host-perfdata
}
go to /usr/local/pnp4nagios/etc/ , rename rra.cfg-sample files to rra.cfg.


Append two entries to /usr/local/nagios/etc/objects/templates.cfg:

define host {
name            host-pnp
action_url      /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_
register        0
}

define service {
name            service-pnp
action_url      /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$
register        0
}
Add above templates to any host or service you want like I change /usr/local/nagios/etc/objects/localhost.cfg
.......
define host{
        use                     linux-server,host-pnp         ; Name of host template to use
                            ; This host definition will inherit all variables that are defined
                            ; in (or inherited by) the linux-server host template definition.
        host_name               localhost
        alias                   localhost
        address                 127.0.0.1
        }

......
define service{
        use                             local-service,service-pnp          ; Name of service template to use
        host_name                       localhost
        service_description             PING
    check_command            check_ping!100.0,20%!500.0,60%
        }
........

Restart nagios and apache2 services like aboves and we will see graph icon in hosts and services was added template.
This is the result:

pnp4nagios graph icon tientuts blog