Tag Archives: script

Monitor the RAID Status Avago LSI Logic SAS3008 Fusion-MPT SAS-3 with Linux

Hi

Need to monitor the RAID Status of your Avago LSI Logic / Symbios Logic SAS3008 PCI-Express Fusion-MPT SAS-3 under Linux with perl?

Yes Avago has a crappy website. When you search the website for SAS3008 you only find some pdf. But not the utility to query your raid controller. Crappy website or intentionally. Who knows ūüôā

Below is a script which send’s a simple mail if something goes bad to your RAID. Just put it in your crontab. Might someone want’s to adopt it. Might use with Nagios/Icinga. Actually I’ve not the case to do this. Might later…

#!/usr/bin/perl

use warnings;
use MIME::Lite;

$emailFrom = 'root@server.domain.tld';
$emailTo = 'hostmaster@yourdomain.tpl';
$smartHost = 'smarthost.mail.local';
$hostName = 'server.domain.tld';
$pathSas3ircu = '/root/bin/SAS3IRCU_P12/sas3ircu_linux_x64_rel/sas3ircu';

if (check_status() == 1) {
  $body = join("", get_info("0","STATUS"));
  send_email($emailTo,$body);
}

sub check_status {
  $error = 0;

  foreach $line (get_info("0","DISPLAY")) {
    if ($line =~ /Status of volume/) {
      if ($line !~/Okay/) {
        $error = 1;
      }
    }
    if ($line =~ /State/) {
      if ($line !~ /Optimal/ ) {
        $error = 1;
      }
    }
  }
  return $error;
}

sub get_info {
  $arg1 = shift;
  $arg2 = shift;

  $cmd = "$pathSas3ircu $arg1 $arg2";
  @output = `$cmd`;
  return @output;
}

sub send_email {
  $arg1 = shift;
  $arg2 = shift;
  
  $subject = "Warning RAID inconsitent $hostName";

  $msg = MIME::Lite->new(
    From     => $emailFrom,
    To       => $arg1,
    Subject  => $subject,
    Data     => $arg2
  );

  $msg->send('smtp',$smartHost,Debug=>0);
}

Here a download link of the tool:
http://docs.avagotech.com/docs/SAS3IRCU_P12.zip

Here a link of an different controller where you find the download link:
http://www.avagotech.com/products/server-storage/host-bus-adapters/sas-9305-16e#downloads

Have Fun!

l2tp ipsec linux client bash script

hi

here is my simple approach of a vpn client via bash
The main script i found https://wiki.archlinux.org/index.php/L2TP/IPsec_VPN_client_setup
I’ve adopted it to my needs.

First we configure strongswan:

/etc/ipsec.conf
conn yourcompany
    keyexchange=ikev1
    authby=secret
    type=transport
    left=%defaultroute
    leftprotoport=17/1701
    right=2.2.2.2
    rightprotoport=17/1701
    auto=add
/etc/ipsec.secrets
2.2.2.2 : PSK "yourpsk"

Now we configure xl2tpd

/etc/xl2tpd/xl2tpd.conf
[lac vpn-connection]
lns = 2.2.2.2
ppp debug = yes
pppoptfile = /etc/ppp/options.l2tpd.client
length bit = yes
/etc/ppp/options.l2tpd.client
ipcp-accept-local
ipcp-accept-remote
refuse-eap
require-mschap-v2
noccp
noauth
idle 1800
mtu 1410
mru 1410
defaultroute
debug
lock
connect-delay 5000
name yourusername
password yourpassword

Here is my bash script

#!/bin/bash
if [ $# != 1 ] ; then
    echo "Usage: (sudo) sh $0 {start|stop}" 
    exit 1;
fi

VPN_ADDR=2.2.2.2

function getIP(){
    /sbin/ifconfig $1 | grep "inet "| awk '{print $2}'
}

function getGateWay(){
    /sbin/route -n | grep -m 1 "^0\.0\.0\.0" | awk '{print $2}'
}

function getVPNGateWay(){
    /sbin/route -n | grep -m 1 "$VPN_ADDR" | awk '{print $2}'
}

function saveInterface() {
    echo $(/sbin/route -n | grep -m 1 "^0\.0\.0\.0" | awk '{print $8}') > /tmp/interface.txt
}

function getInterface(){
    cat /tmp/interface.txt
}

GW_ADDR=$(getGateWay)  

function start(){
    saveInterface
    ipsec up youconnectioname
    sleep 2    #delay to ensure that IPsec is started before overlaying L2TP

    systemctl start xl2tpd
    sleep 2
    /bin/echo "c vpn-connection" > /var/run/xl2tpd/l2tp-control     
    sleep 2    #delay again to make that the PPP connection is up.

    route add $VPN_ADDR gw $GW_ADDR $(getInterface)
    route add default gw $(getIP ppp0)
    route delete default gw $GW_ADDR
}

function stop(){
    ipsec down yourconnectioname
    /bin/echo "d vpn-connection" > /var/run/xl2tpd/l2tp-control
    systemctl stop xl2tpd
    
    VPN_GW=$(getVPNGateWay)
    route delete $VPN_ADDR gw $VPN_GW $(getInterface)
    route add default gw $VPN_GW
}
$1
exit 0

awstats static html apache ubuntu howto

hi

here some nice howto to get awstats with static html output working under ubuntu

apt-get install awstats libgeo-ipfree-perl libnet-ip-perl

disable the ubuntu cronjob ( comment out everything)

vim /etc/cron.d/awstats

now we setup our /etc/awstats/awstats.domain.tld.conf (cp awstats.conf awstats.domain.tld.conf)

LogFile="/var/log/apache2/domain.tld-access.log"
LogFormat=1
SiteDomain="domain.tld"
DNSLookup=0
LoadPlugin="graphgooglechartapi"
LoadPlugin="geoipfree"

I’ve disabled DNSLookup due to performance issues

create a shell script witch executes awstats

#!/bin/bash

DOMS="domain.tld domain1.tld domain2.tld domain3.tld"

for DOM in $DOMS
do
/usr/lib/cgi-bin/awstats.pl -config=$DOM -update -LogFile="/usr/share/awstats/tools/logresolvemerge.pl /var/log/apache2/"$DOM"-access.log.1 /var/log/apache2/"$DOM"-access.log |"
/usr/share/awstats/tools/awstats_buildstaticpages.pl -update -config=$DOM -dir=/srv/www/vhosts/host1/$DOM/htdocs/awstats -awstatsprog=/usr/lib/cgi-bin/awstats.pl
done

Have fun!

Mikrotik SSTP 100% CPU Load

Hi

I’ve seen that due to some https requests the mikrotik SSTP server uses 100% of CPU
Here some nice script with scheduler which reenables the SSTP server. I’ve seen the bug with the latest ROS 5.20.

/system script
 add name=cpuload policy=ftp,read,write,winbox,api source=":local cpuload [ /system resource get cpu-load ]\r\
 \nif ( \$cpuload = 100 ) do {\r\
 \n/interface sstp-server server set enabled=no\r\
 \n/interface sstp-server server set enabled=yes\r\
 \n:log warning \"CPU Load \$cpuload reenabled sstp service\"\r\
 \n}"

Here the scheduler:

/system scheduler
add disabled=no interval=5m name=cpuloadsstp on-event="/system script run cpuload" policy=ftp,read,write,winbox,api start-date=\
    sep/28/2012 start-time=07:00:33

Have fun!

Get Austrian subnets from Ripe database

Hi
Need from the ripe database the subnets in cidr of some specific country?
Here my nooby approach to get this done.

wget ftp://ftp.ripe.net/pub/stats/ripencc/delegated-ripencc-latest
vim ripeconvert.pl

Paste the following code:

#!/usr/bin/perl

%subnet =();
$subnet{'4'} = "30";
$subnet{'8'} = "29";
$subnet{'16'} = "28";
$subnet{'32'} = "27";
$subnet{'64'} = "26";
$subnet{'128'} = "25";
$subnet{'256'} = "24";
$subnet{'512'} = "23";
$subnet{'1024'} = "22";
$subnet{'2048'} = "21";
$subnet{'4096'} = "20";
$subnet{'8192'} = "19";
$subnet{'16384'} = "18";
$subnet{'32768'} = "17";
$subnet{'65536'} = "16";
$subnet{'131072'} = "15";
$subnet{'262144'} = "14";
$subnet{'524288'} = "13";
$subnet{'1048576'} = "12";
#special ripe database
$subnet{'768'} = "22";
$subnet{'1280'} = "21";
$subnet{'1536'} = "21";
$subnet{'2560'} = "20";
$subnet{'2816'} = "20";
$subnet{'3072'} = "20";
$subnet{'9216'} = "18";
$subnet{'12288'} = "18";
$subnet{'13312'} = "18";

open(INFO,"<delegated-ripencc-latest");
        @ripe = <INFO>;
close(INFO);

sort(@ripe);

foreach $data (@ripe) {
    chomp($data);
    if ( $data =~ /ipv4/ && $data =~ /AT/ ) {
        @sdata = split('\|',$data);
        print @sdata[3]."\/".$subnet{"@sdata[4]"}."\n";
    }
    if ( $data =~ /ipv6/ && $data =~ /AT/ ) {
        @sdata = split('\|',$data);
        print @sdata[3]."\/".@sdata[4]."\n";
    }
}
perl ripeconvert.pl

Have fun!