Archive for the ‘Linux/Unix’ Category

The beauty of LVM

Friday, July 7th, 2006

I was running low on disk space on one of my servers. Luckily I had set up LVM, was using XFS and had some room to spare on my physical volume. With just 2 commands I added 1GB of space to the filesystem.

root ~> lvextend -L+1G /dev/vg00/rra
root ~> xfs_growfs /usr/local/cacti/rra

I found out how much space I had to spare using the vgdisplay command.

root ~> vgdisplay
— Volume group —
VG Name vg00
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 7
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 5
Open LV 5
Max PV 0
Cur PV 1
Act PV 1
VG Size 67.10 GB
PE Size 4.00 MB
Total PE 17178
Alloc PE / Size 9728 / 38.00 GB
Free PE / Size 7450 / 29.10 GB
VG UUID vYM9vS-mmUn-2JUm-GLJB-B1gk-dJ2r-FHuCZU

Looking at “Free PE” you can see I have 29GB to use on down the road.

To learn more about lvm, check out the HOWTO

Perl GetOpt Not Working

Thursday, July 6th, 2006

I have run into this same problem a few times so I am documenting it here. When using GetOpt::Long and friends I would be mystified when the options were ignored. For example:

#!/usr/bin/perl

use strict;
use warnings;
use Getopt::Long;
my $debug = 0;

my $result = GetOptions( "debug" => $debug );
print "Debug flag is $debug\\n";
wriley ~/bin> ./getopttest.pl
Debug flag is 0
wriley ~/bin> ./getopttest.pl --debug
Debug flag is 0
wriley ~/bin>

The options are completely ignored! A short time of googling later and I remembered the solution.

#!/usr/bin/perl

use strict;
use warnings;
use Getopt::Long;
my $debug = 0;

my $result = GetOptions( "debug" => \\$debug );
print "Debug flag is $debug\\n";
wriley ~/bin> ./getopttest.pl
Debug flag is 0
wriley ~/bin> ./getopttest.pl --debug
Debug flag is 1
wriley ~/bin>

The key is escaping the $ in the GetOptions() statement. If you don’t escapey, it don’t workey!

Adding a large number of devices to Cacti

Wednesday, June 28th, 2006

There is a very nice open source snmp graphing and monitoring package avaiable called cacti. I have used it for almost a year now and have been very pleased with its functionality and ease of use.

Recently at work I had the need to graph a large number (300) of network devices and a handful of Linux servers. Being the sort of guy that would rather write scripts than manually enter 300 devices via the cacti web interface, I cobbled together some perl and php code. I had a list of network devices in a CSV file.

The format of the file is:

ID,City,State,IP Address.

If you use the scripts below you will need to edit them to fit your own device data. They are provided for illustration purposes and will most likely not work for you “out of the box”.

Update See this thread for more advanced scripts.

Process to add hosts and create graphs for each

  1. fixCSV.pl Branches.CSV branches.csv
  2. Check branches.csv for empty IP address fields and remove
  3. mkBranchSql.pl branches.csv > branches.sql
  4. branches.sql ==> DB
  5. make_host_graph.pl branches.csv > host_graph.sql
  6. host_graph.sql ==> DB
  7. make_host_snmp_query.pl branches.csv > host_snmp_query.sql
  8. host_snmp_query.sql ==> DB
  9. foreach host_id do php run_data_query.php $host_id
  10. foreach host_id do php run_host_new_graphs.php $host_id
  11. Clear Poller Cache (php rebuild_poller_cache.php)

Process to add each host to proper state in graph tree

  1. create alphabetical flat file of state abbreviations, states
  2. mkBranchStatesSql.pl states > branches-states.sql
  3. branches-states.sql ==> DB
  4. mkGraphTreeSql.pl branches.csv > graph_tree_items.sql

Autocreate thresholds

  • foreach host_id do php run_autocreate.php $host_id

Files

Perl

PHP

$%#@&!! DOS

Tuesday, June 27th, 2006

If someday you should find yourself launching your head with much force against a masonry wall, wailing to all that will listen of the futility of expecting kickstart to work as designed…

Check your kickstart file for DOS line endings. Trust me. They break stuff.

🙂