A nagios plugin to check Tomcat Apps

February 5th, 2014

I wrote a simple nagios plugin to check the status of tomcat webapps.
Instead of looking pages like this one…
click to enlarge
I’d better to use some script like this.
To put the plugin in the nagios environment, add these lines

define command{
command_name check_tomcat_app
command_line /bin/bash /usr/lib/nagios/plugins/check_tomcat_app $ARG1$ $ARG2$ $ARG3$
}

to the commands.cfg file definitions.Then add some line like theese

define service{
use generic-service
host_name myhostname
service_description Examples Web Service
is_volatile 0
check_period 24×7
max_check_attempts 3
normal_check_interval 15
retry_check_interval 1
contact_groups admins
notification_interval 240
notification_period 24×7
notification_options c,r
check_command check_tomcat_app!”http://tomcatserver.my.lan:8080/manager/html/list”!Examples!admin:passw
}

into the services.cfg file.
Off corse username and password has to be set up in tomcat-users.xml file

$ cat /usr/local/apache-tomcat/conf/tomcat-users.xml
<?xml version=’1.0′ encoding=’utf-8′?>
<tomcat-users>
<role rolename=”manager”/>
<role rolename=”admin-gui”/>
<role rolename=”manager-gui”/>
<role rolename=”manager-status”/>
<user username=”admin” password=”passw” roles=”manager,manager-gui,manager-status,admin-gui”/>
</tomcat-users>

How to remove the read failed after 0 of 4096 I/O error

September 18th, 2013

Recently in a very old server I had to remove a disk. My server was composed by two physical volumes: a RAID5 volume, shown as /dev/sda  to the operating system  by the SCSI controller, and a single hard disk as /dev/sdb.

My /dev/sdb, since there is no way to have a new disk with the same geometry, I decided to remove it.
The bios utility of my SCSI controller is quite strange and I cannot remove my une-disk logical volume without remove all the configuration.

root@arch:~# pvdisplay
  /dev/sdb: read failed after 0 of 4096 at 0: input/output Error
  /dev/sdb: read failed after 0 of 4096 at 146695716864: input/output Error
  /dev/sdb: read failed after 0 of 4096 at 146695774208: input/output Error
  /dev/sdb: read failed after 0 of 4096 at 4096: input/output Error
  — Physical volume —
  PV Name               /dev/sda1
  VG Name               vg_system
  PV Size               838,12 GiB / not usable 2,00 MiB
  Allocatable           yes
  PE Size               4,00 MiB
  Total PE              214559
  Free PE               21184
  Allocated PE          193375
  PV UUID               ZQQwAs-yGgP-LZXk-3cTy-yaOb-gijr-bnUCz4

So I’d better to leave my controller untouched and tell my linux CentOS to forget the /dev/sdb disk.

root@arch:~# echo 1 > /sys/block/sdb/device/delete

x2go

May 3rd, 2013

Thanks to a Sebastian’s post here, I noticed the existence of  x2go. I’ve just tested it and I liked it a lot. X2go is a very nice way to access my linux desktop.

In order to install x2go server-side, on a Centos 6.4 I only needed theese commands:

yum update
wget -O /etc/yum.repos.d/x2go.repo http://download.opensuse.org/repositories/X11:/RemoteDesktop:/x2go/RHEL_6/X11:RemoteDesktop:x2go.repo
yum update
yum install x2goserver

then

vi /etc/group

to add the guys to be allowed to connect to their desktop. E.g.

x2gouser:x:298:joe,jane,jack,jasmine

The x2go windows client can be downloaded from http://code.x2go.org/releases/binary-win32/x2goclient/releases/.

a self-made log statistics with wordpress

August 14th, 2012

It’s not the case of freeshell.de or nic-nac-project.de that kindly is hosting this blog, but in the world there are some low cost hosting profiles where You can’t access your weblog.
Several times the webserver logs nothing at all.
Since I think  it’s a nice thing to have my web access statistics, if Your wordpress blog is on such kind of webserver, I suggest to add some plugin to your wordpress installation, such as myStat.

Once I preferred to write my own the http access log, in order to process it with awstats.
To do this, I changed the footer.php of my wordpress theme adding theese lines after the </html> tag:

<?php wp_footer(); ?>
</body>
</html>
<?php
// kludge to write a sort of access log on a file….
$monthyear = date(“F-Y”);
$remoteip = getenv(‘REMOTE_ADDR’);
$mytimestamp = date(“d/M/Y:G:i:s T”);
$useragent= getenv(“HTTP_USER_AGENT”);
$requri= getenv(“REQUEST_URI”);
$reqmet= getenv(“REQUEST_METHOD”);
$referrer= getenv(“HTTP_REFERER”);
$docroot= getenv(“DOCUMENT_ROOT”);
$logdir= $docroot . “/bloglog”;
$fplog = fopen($logdir .”/accesslog-myblog-“.$monthyear.”.txt”, “a+”);
fprintf ($fplog, “%s – [%s] \”%s %s\” \”%s\” \”%s\” 200\n”,
$remoteip, $mytimestamp,
$reqmet, $requri,
$useragent, $referrer);
fclose ($fplog);
?>

Doing so, a web access to any page of my site will add a log line into the accesslog-myblog-August-2012.txt  file. This file is into a directory named bloglog at the root of the webpages.

Getting this file and putting it on a linux box with awstats installed, it’s easy to generate my web statistics.

 

First I have to create a /etc/awstats/awstats-myblogname.conf telling my LogFile path and my LogFormat

LogFormat = “%host – %time1 %methodurlnoprot %uaquot %refererquot %code”

Then I have to run

 /usr/share/awstats/tools/awstats_updateall.pl now         -configdir=”/etc/awstats”         -awstatsprog=”/usr/share/awstats/wwwroot/cgi-bin/awstats.pl”

in order to read my stats at http://my-awstats-server.local/awstats/awstats.pl?config=myblogname

migrating from Microsoft DHCP to ISC

February 23rd, 2012

I’ve just finished a quick and dirty perl script to help me in moving my DHCP server from a Micro$oft 2003 Server to Linux.

This script reads the dump file created by netsh and writes a dhcpd.conf file.
First step, on the Microsoft DHCP host, dump the configuration:

C:\temp>netsh dhcp server \\servername dump > dhcp.dump

Second step, use the perl script:

perl ./w2ldhcpcfg.txt -i dhcp.dump -o dhcpd.conf

On the net, there is a rexx script too. It can be found here.

set default Openoffice format to Micro$oft

February 10th, 2012

To set Openoffice default file format, just go to
Options -> Load/Save -> General
and change the “Always save as” value.

NO_PUBKEY error in apt-get update

January 25th, 2012

After editing Your /etc/apt/sources.list file, probably you will get a warning message in the output of the apt-get update command. The warning message will be like this:

W: GPG error: http://ppa.launchpad.net natty Release: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY E9DDA5AAC586799E

You can remove this message in two step:

root@myhost:~# gpg —-keyserver pgpkeys.mit.edu —-recv-key 2E2BCDBCB38A8516

gpg: requesting key B38A8516 from hkp server pgpkeys.mit.edu

gpg: /root/.gnupg/trustdb.gpg: trustdb created

gpg: key B38A8516: public key “Oracle OSS group (Open Source Software group) ” imported

gpg: Total number processed: 1

gpg: imported: 1

root@myhost:~# gpg -a —-export 2E2BCDBCB38A8516 | sudo apt-key add –

OK

winexe to interact from linux to windows hosts

November 24th, 2011

With pstools You can run any command from your Windows PC to any other one. A valid command line alternative to pstools for the linux operating system is winexe.

To install winexe un a natty-ubuntu host (maybe it will work on a quite new debian too), You can add theese twho lines to your sources.list file:

deb http://ppa.launchpad.net/jdthood/winexe/ubuntu natty main

deb-src http://ppa.launchpad.net/jdthood/winexe/ubuntu natty main

then

apt-get update && apt-get install winexe

Once installed winexe, you can do useful things like

winexe //myserver1 –user “DOMAIN\\user” “tasklist /FI \”CPUTIME gt 00:00:10\””

or simply

winexe //myserver2 –user “Administrator” cmd

and many others! 🙂