Archive for cygwin

Nagios 3 on Cygwin

Don't think Nagios can be fully built on Cygwin. I still have one compile error related to ICMP include files. Basically, Cygwin doesn't have a valid ICMP port and icmp.h file is empty. Other than that, I got it to build and run thanks to all the related discussions out there.

Install on Cygwin

Solutions for "error: storage size of 'hints' isn't known" Error

* Download cygwin-1.5.25-15-ipv6-0.23.zip from http://win6.jp/Cygwin/.
* Unzip at Cygwin root diretory.

 
cd \
unzip cygwin-1.5.25-15-ipv6-0.23.zip
cd cygwin-1.5.25-15-ipv6-0.23
tar cvf ipv6.tar bin lib usr
cp ipv6.tar ..
cd ..
tar xvf ipv6.tar
cd bin
mv cygwin1.dll cygwin1.dll.old
mv new-cygwin1.dll cygwin1.dll
 

Download and Install

Install Cygwin dependencies

* Graphics/gd
* Graphics/jpeg
* Graphics/libgd-devel
* Graphics/libpng
* Web/Apache2
* Web/Apache2-devel

Compile and Install Nagios Core

* Download Nagios core from http://www.nagios.org/download/

 
mkdir -p /opt/nagios /etc/nagios /var/nagios
cd /cygdrive/c/sw/nagios/
gunzip nagios-3.2.0.tar.gz
tar xf nagios-3.2.0.tar
cd nagios-3.2.0
sh configure \
    --prefix=/opt/nagios \
    --sysconfdir=/etc/nagios \
    --localstatedir=/var/nagios \
    --libexecdir=/opt/nagios/plugins \
    --with-nagios-user=ming-lj\
    --with-nagios-group=mkgroup-l-d \
    --with-command-group=mkgroup-l-d \
    --with-mail=/usr/sbin/ssmtp.exe \
    --enable-cygwin
# Comment out all occurrences of modules in MakeFile file to avoid helloworld.c error.
make all
make install
make install-commandmode
make install-config
 

Download and Install Nagios Plug-ins

* Install Cygwin dependencies
- System/procps. This is needed since Cywin ps command is not compatible to Linux ps command (procps does).
- System, Net/ping
* Download Nagios plug-ins from http://www.nagios.org/download/plugins/

 
gunzip nagios-plugins-1.4.14.tar.gz
tar xf nagios-plugins-1.4.14.tar
cd cd nagios-plugins-1.4.14
 
# Global replace 127.0.0.1 to 64.233.169.99 which is for www.google.com. This is needed in order for ping to succeed.
 
sh configure \
    --prefix=/opt/nagios \
    --sysconfdir=/etc/nagios \
    --localstatedir=/var/nagios \
    --libexecdir=/opt/nagios/plugins \
    --with-nagios-user=Ming-LJ \
    --with-nagios-group=mkgroup-l-d \
    --with-ipv6=no \
    --with-ps-command="`which procps` -eo 's uid pid ppid vsz rss pcpu etime comm args'" \
    --with-ps-format='%s %d %d %d %d %d %f %s %s %n' \
    --with-ps-cols=10 \
    --with-ps-varlist='procstat,&procuid,&procpid,&procppid,&procvsz,&procrss,&procpcpu,procetime,procprog,&pos'    
 
#####################
# Edit plugins/Makefile
# Move negate$(EXEEXT) urlize$(EXEEXT) to the end
# Append $(EXEEXT) to check_dns, check_by_ssh, check_swap, check_nt
#####################
libexec_PROGRAMS = check_apt$(EXEEXT) check_cluster$(EXEEXT) \
  check_disk$(EXEEXT) check_dummy$(EXEEXT) check_http$(EXEEXT) \
  check_load$(EXEEXT) check_mrtg$(EXEEXT) \
  check_mrtgtraf$(EXEEXT) check_ntp$(EXEEXT) \
  check_ntp_peer$(EXEEXT) check_nwstat$(EXEEXT) \
  check_overcr$(EXEEXT) check_ping$(EXEEXT) check_real$(EXEEXT) \
  check_smtp$(EXEEXT) check_ssh$(EXEEXT) check_tcp$(EXEEXT) \
  check_time$(EXEEXT) check_ntp_time$(EXEEXT) check_ups$(EXEEXT) \
  check_users$(EXEEXT) check_procs$(EXEEXT) check_nagios$(EXEEXT) \
  check_dns$(EXEEXT) check_by_ssh$(EXEEXT) check_swap$(EXEEXT) check_nt$(EXEEXT) \
  negate$(EXEEXT) urlize$(EXEEXT)
 
#####################
# Add to plugins/config.h file #
#####################
#define PS_COLS 10
#define PS_COMMAND "/usr/bin/procps -eo 's uid pid ppid vsz rss pcpu etime comm args'"
#define PS_FORMAT "%s %d %d %d %d %d %f %s %s %n"
#define PS_USES_PROCETIME "yes"
#define PS_VARLIST procstat,&procuid,&procpid,&procppid,&procvsz,&procrss,&procpcpu,procetime,procprog,&pos
#define PING_COMMAND "/usr/bin/ping"
 
make -i all
make -i install
 

References

http://www.debianhelp.co.uk/nagiosinstall.htm
http://nagios.sourceforge.net/docs/3_0/toc.html

Setup Cygwin Cron

* Install "Admin/cron"
* Install "Admin/cygrunsrv"
* Install "Editors/vim"
* Start Cron as a service

For *Non* Windows 2003 Servers

 
$ cron-config
Cron is already installed as a service under account NAUser-Name.
Do you want to remove or reinstall it? (yes/no) yes
OK. The cron service was removed.
 
Do you want to install the cron daemon as a service? (yes/no) yes
Enter the value of CYGWIN for the daemon: [ntsec smbntsec] ntsec
 
The service can run either as yourself or under a privileged account.
Running as yourself allows better access to network drives,
but does not allow to run the crontab of other users.
Do you want to the cron daemon to run as yourself? (yes/no) yes
 
Please enter the password for user 'User-Name':
Reenter:
*******************************************************************
* Warning: User mode mounts detected.  This will likely cause     *
* the service to fail to start.  You must have system mode mounts *
* in order to run services.  Re-run setup and choose 'All Users'  *
* or consult the FAQ for more information.                        *
*******************************************************************
Running cron_diagnose ...
... no problem found.
 
Do you want to start the cron daemon as a service now? (yes/no) yes
OK. The cron daemon is now running.
 
In case of problem, examine the log file for cron,
/var/log/cron.log, and the Windows event log (using /usr/bin/cronevents)
for information about the problem cron is having.
 
Examine also any cron.log file in the HOME directory
(or the file specified in MAILTO) and cron related files in /tmp.
 
If you cannot fix the problem, then report it to cygwin@cygwin.com.
Please run the script /usr/bin/cronbug and ATTACH its output
(the file cronbug.txt) to your e-mail.
 

For Windows 2003 Server

* Add a user called cron_server to run cron service

$ net user cron_server passwd /add /active:yes /fullname:"Cron Server" /comment:"Cygwin Cron Server"

* Add user cron_server to Administrators group

$ net localgroup Administrators cron_server /add

* Modify user cron_server rights

$ editrights -a SeAssignPrimaryTokenPrivilege -u cron_server
$ editrights -a SeCreateTokenPrivilege -u cron_server
$ editrights -a SeIncreaseQuotaPrivilege -u cron_server
$ editrights -a SeServiceLogonRight -u cron_server
$ editrights -a SeDenyInteractiveLogonRight -u cron_server
$ editrights -a SeDenyNetworkLogonRight -u cron_server
$ editrights -a SeDenyRemoteInteractiveLogonRight -u cron_server

* Sync up Cygwin passwd file

$ mkpasswd -l >

Use WebInject/Cygwin For Web Monitoring

Install Cygwin

See this post for details.
In addition
* Install all Perl packages.
* Install "devel/make" and all its dependencies.
* Install "devel/gcc-core" and "devel/gcc-g++" packages.
* Install "openssl" and "openssl-devel" packages.
* Install "mail/ssmtp" package.

 
ssmtp-config
 

Install from CPAN

* Install "XML::Simple"

 
shell> perl -MCPAN -e shell
cpan> install XML::Simple
 
OR
cd .cpan/build/XML-Simple-2.18-ICtnsp
make test
make install
 

* Install "Crypt::SSLeay"

 
shell> perl -MCPAN -e shell
cpan> install Crypt::SSLeay
 
OR
cd .cpan/build/Crypt-SSLeay-0.57-MJnTGM
perl Makefile.PL
make test
make install
 

* Install "Error" pacakge

 
shell> perl -MCPAN -e shell
cpan> install Error
 
* Create a new ParserDetails.ini file in the /usr/lib/perl5/vendor_perl/5.10/XML/SAX directory
<pre>
[XML::SAX::PurePerl]
http://xml.org/sax/features/namespaces = 1
 
[XML::LibXML::SAX::Parser]
http://xml.org/sax/features/namespaces = 1
 
[XML::LibXML::SAX]
http://xml.org/sax/features/namespaces = 1
 

Install WebInject

* Download WebInject from its download page. I downloaded the source version webinject-1.41.src.tar.gz.
* Unzip webinject-1.41.src.tar.gz into a local directory.

Run WebInject

 
./webinject.pl
 

Configure External Email Module

* Create an external email module named "Plugin.pm":

 
 
if ($casefailedcount > 0) {
open(MAIL, '| /usr/sbin/ssmtp.exe me\@my.com') or "die";
print MAIL <<EOF;
To:me\@my.com
From:me\@my.com
Subject:Passed: $casepassedcount,  Failed: $casefailedcount
 
Start Time: $currentdatetime \n
Total Run Time: $totalruntime seconds \n
\n
Test Cases Run: $totalruncount \n
Test Cases Passed: $casepassedcount \n
Test Cases Failed: $casefailedcount \n
Verifications Passed: $passedcount \n
Verifications Failed: $failedcount \n
\n
Average Response Time: $avgresponse seconds \n
Max Response Time: $maxresponse seconds \n
Min Response Time: $minresponse seconds \n
EOF
}
 
1;
 

* Add to config.xml:

 
<reporttype>external:/path/to/Plugin.pm</reporttype>
 

Setup as cron job

* Setup Cygwin cron service as described in this post
* Setup crontab for webinject to run every 30 min:

 
crontab -e
*/30 * * * * /cygdrive/c/webinject/webinject.pl
 

Cygwin/X SSH

Install Cygwin/X and OpenSSH
* Download Cygwin setup.exe from cygwin.com. There is no difference between "Install Cygwin Now" and "Install Cygwin/X Now" buttons.
* Move setup.exe to a local folder where you would also like to store downloaded Cygwin files, e.g. c:\download\cygwin.
* Double click setup.exe to startup download and installation.
- Choose Install from internet
- Set root directory, e.g. c:\cygwin.
- Accept Local Package Directory, e.g. c:\download\cygwin.
- Choose Direct Connection if you're directly connected to the internet.
- Choose download site, e.g. ftp://ftp.gtlib.gatech.edu.
- Select to install the whole X11 category at the bottom of the package list by clicking the two-arrow symbol until text after it changes to "install".
- Click the "View" button so all the packages are listed alphabetically.
- Find "openssh" package. Click the double-arrow symbol until the text after it changes to install or package version numbers.
- Click Next and wait for the selected packages (Cygwin, X11 and openssh) to be downloaded and installed.
- Click Finish when done.

Start Cygwin/X SSH Session
* Click Cygwin shortcut to bring up the Cygwin window.
* Type "startx" to bring up the Cygwin/X window (Cygwin/X:0.0).
* In one of the xterm, type

ssh -Y -l username remote_hostname_or_ip_address

* Remote X windows such as Java GUI can now be shown on Cygwin/X.

References
Cygwin/X User's Guide
Cygwin SSH Notes

Misc Commands

# sync up local accounts
$mkpasswd -l > /etc/passwd

# Using an alternate home root
$ mkpasswd -l -p "$(cygpath -H)" > /etc/passwd

Uninstall Cygwin from Windows XP

* Remove all installed services

# Remove sshd service
$ cygrunsrv --stop sshd
$ cygrunsrv --remove sshd
$ net user sshd delete

# Remove cron service
$ cygrunsrv --stop cron
$ cygrunsrv --remove cron
$ net user cron delete

# Remove syslog-ng service
$ cygrunsrv --stop syslog-ng
$ cygrunsrv --remove syslog-ng

* Delete the folder c:\cygwin and all its sub-folders.
* Remove the Environment Variable CYGWIN.
* Edit the Environment path accordingly.
* Start -> Run -> regedit and delete these two registry trees

"HKEY_CURRENT_USER_Software_Cygnus Solutions"
"HKEY_LOCAL_MACHINE_Software_Cygnus Solutions"

* Go to Control Panel -> Category View -> Performance and Maintenance -> Administrative Tools -> Computer Management (or click Start -> Run -> compmgmt.msc):
- Delete the sshd user if it exists in the "System Tools" - "Local Users and Groups" - "Users" section.
- Delete cron user if it exists in the "System Tools" - "Local Users and Groups" - "Users" section.
Reference: http://pigtail.net/LRP/printsrv/remove-cygwin.html