Arrow Keys In Vim
When you navigate using the arrow keys in vim, you might get some funny characters like A, B, C…etc. In .vimrc, add this line:
:set nocompatible
This should do the trick.
When you navigate using the arrow keys in vim, you might get some funny characters like A, B, C…etc. In .vimrc, add this line:
:set nocompatible
This should do the trick.
If you wish to check that your web application is working fine (people are able to login), you can run a script to automate the login process. It is possible to use cron to do it but with nagios, you could do much more. Nagios is highly configurable and it makes perfect sense to write a plugin just to do that.
I wrote a perl script over the weekend to simulate logins into a website once every 2 mins. If login fails after 2 tries, an email alert will be sent to the administrator (Settings can be changed in Nagios). The script works by detecting a certain html pattern from the result generated by the login success webpage. An example of the command in action is something like this:
check_login -f 1 -u http://xxx.com/index.php -l xx -p xx -L Username -P Password -r ‘Logout.jsp’
* L is the Userid field in the form and P is the password field in the form.
* u is the FULL url including the http.
* l is the actual login name and p is the actual login password.
* r is the regex pattern to search for if the login is successful.
* f is the form number. If you have 2 forms in the login page, the 1 will be the first form.
For the script to work, you need perl and its mechanize library. Copy and paste this script into the default plugin folder - likely to be /usr/lib/nagios/plugins. Add ‘check_login’ to hosts.cfg and define it in commands.cfg (or checkcommands.cfg). Refer to the nagios doc if unsure. The script is backward compatible with netsaint.
#!/usr/bin/perl -Tw
use strict;
use Getopt::Long;
use WWW::Mechanize;
use vars qw($opt_v $opt_h $opt_u $opt_f $opt_r $opt_l $opt_L $opt_P $opt_p $PROGNAME);
use lib “/usr/lib/nagios/plugins” ;
use utils qw(%ERRORS &print_revision &support &usage);
my($PROGNAME) = $0 =~ m/([^\/]+)$/;
sub print_help ();
sub print_usage ();
delete $ENV{PATH};
delete $ENV{BASH_ENV};
delete $ENV{ENV};
Getopt::Long::Configure(’bundling’);
GetOptions(
‘v|version’ => \$opt_v,
‘h|help’ => \$opt_h,
‘u|url=s’ => \$opt_u,
‘l|login=s’ => \$opt_l,
‘p|password=s’ => \$opt_p,
‘f|formnumber=s’ => \$opt_f,
‘r|logoutregex=s’ => \$opt_r,
‘L|loginfield=s’ => \$opt_L,
‘P|passwordfield=s’ => \$opt_P,
);
if ($opt_v) {
print_revision($PROGNAME,’$Revision: 1.0 $’);
exit $ERRORS{’UNKNOWN’};
}
if ($opt_h) {
print_help(); exit $ERRORS{’UNKNOWN’};
}
#### PREDEFINE FIELDS
$opt_L = ($opt_L ? $opt_L : “Username”);
$opt_P = ($opt_P ? $opt_P : “Password”);
#### CHECKING REQUIRED FIELDS
sub error($$)
{
my($code, $msg) = @_;
print($msg, “\n”);
exit $ERRORS{$code};
}
($opt_f) || error(’UNKNOWN’, ‘You need to specify a form number.’);
($opt_u) || error(’UNKNOWN’, ‘You need to specify a url.’);
($opt_l) || error(’UNKNOWN’, ‘You need to specify a login name.’);
($opt_p) || error(’UNKNOWN’, ‘You need to specify a passwd.’);
($opt_r) || error(’UNKNOWN’, ‘You need to specify a logout regex.’);
my $agent = WWW::Mechanize->new();
$agent->get($opt_u);
$agent->form_number($opt_f);
$agent->field($opt_L,$opt_l);
$agent->field($opt_P,$opt_p);
$agent->click();
my $success = $agent->follow_link( url_regex => qr/$opt_r/i);
unless ($success) {
error(’CRITICAL’, “$opt_u login failed.\n”);
}
error(’OK’, “$opt_u login success.\n”);
sub print_usage ()
{
print <
Usage: $PROGNAME [-u URL] [-l login] [-p password] [-L loginfield] [-P=passwordfield] [-f formnumber] [-r logoutregex]
Required Arguments:
-u, –URL==STRING
URL of the site you want to login from.
-l, –login=STRING
login username.
-p, –password=STRING
login passwd.
-L, –loginfield=STRING
Name of the login field in the form.
-P, –passwordfield=STRING
Name of the passwd field in the form.
-f, –formnumber=INT
Form Number on the login page.
-r, –logoutregex=STRING
Regex URL to logout
END
}
sub print_help () {
print_revision($PROGNAME,’$Revision: 1.0 $’);
print <
Bernard Peh, November 2007
This nagios plugin simulates a remote login using perl mechanize library. It attempts to login from a url, check for a logout regex, then logout by itself.
This can be useful to make sure a website or database connection is alive.
END
print_usage();
support();
}
I installed a linux network printer for a friend and thought I post the steps here. First of all, find out the ip address of the printer. Go to http://localhost:631 to add a printer. You might need root access.
Under device, choose ipp and in Device URI, type ipp://hostname/ipp/. Then add the model and follow through the rest of the prompts. When you have finished, go to http://localhost:631/printers/ and you should see your printer listed there. do a test print. If it works, congrats. If not, click on modify printer and under Device URI try using socket://address:9100 instead of ipp. The later seems to work quite well with alot of printers. if in doubt, always telnet host 9000 to see if the port is accessible.
If you do not have access to cups via http://localhost:631, just edit the printers.conf file
vi /etc/cups/printers.conf
the config will be something like this:
Info HP laserjet 4100
Location myhouse
DeviceURI socket://your-ip:9100
State Idle
StateTime 1189572516
Accepting Yes
Shared Yes
JobSheets none none
QuotaPeriod 0
PageLimit 0
KLimit 0
OpPolicy default
ErrorPolicy stop-printer
when done, do a “sudo /etc/init.d/cupsys restart”
hopefully, everything should be working.
I find remembering passwords the hardest thing in life. When creating user accounts on the net, we often need the username and password. To save trouble, a lot of people use the same username and password in alot of places - including bank accounts!
Not every website uses encryption for password, so if you happen to register yourself in a hacker’s website, the hacker might use your username and password to try and login to other websites. Account Registration is always necessary but remember to keep a few low security user id and passwords for untrusted site. Some comon sense stuff but people don’t practice it.
if you are using vim and tries to copy and paste between windows or shells, you may find that vim adds some extra spaces / identations to your code. Irritation? yes. The quick solution is to do a
:set noautoident
or add this in the vimrc file to make it a default.