[root@adserver ~]# ./findilos 172.17.17.0/24
Scanning...
--------------- ------ -------- ------------ ------------------------- -------------------- -----------------------------
iLO IP Address iLO HW iLO FW Server S/N Server Model iLO Edition iLO Licence Key
--------------- ------ -------- ------------ ------------------------- -------------------- -----------------------------
172.17.17.xxx iLO-3 1.26 CN71xxxMxx ProLiant DL360 G7 iLO 3 Advanced xxxxx-xxxxx-xxxxx-xxxxxx-xxxxx
1 iLOs found on network target 172.17.17.0/24
[root@adserver ~]#
スクリプトの修正例は以下
#!/bin/bash
#
# findilos - Search a local network segment for iLOs
# The iLO is the Integrated Lights-Out management processor
# used on HP ProLiant and BladeSystem servers
#
scriptversion="1.0"
#
# Author: iggy@nachotech.com
#
# Website: http://blog.nachotech.com
#
# Requires: tr sed expr curl nmap
#
# Tested with: Nmap 4.20, curl 7.17.1, RHEL4
#
# Note: Discovery of an iLO is dependent upon the Virtual Media port
# being set to the default of 17988. If this has been changed
# by the iLO administrator, then this script will NOT find it.
#
# Also, if the iLO XML Reply Data Return has been Disabled by
# the iLO administrator, this script will not be able to
# gather any information about the server. It will still be
# discovered, but all you will see is its IP address.
#
# GLOBAL VARIABLES
scriptname="findilos"
iloips="/tmp/tmpilos.$$"
iloxml="/tmp/tmpiloxml.$$"
ilohwvers="/tmp/tmpilohwvers.$$"
declare -i ilosfound=0
# FUNCTIONS
function parseiloxml {
fgrep "$1" $iloxml > /dev/null 2>&1
if [ $? -ne 0 ]
then
# tag not found in xml output, return empty string
parsedstring="N/A"
else
# tag was found - now we parse it from the output
tempstring=$( cat $iloxml | tr -d -c [:print:] | sed "s/^.*<$1>//" | sed "s/<.$1.*//")
# trim off leading and trailing whitespace
parsedstring=`expr match "$tempstring" '[ \t]*\(.*[^ \t]\)[ \t]*$'`
fi
}
function is_installed {
which $1 > /dev/null 2>&1
if [ $? -ne 0 ]
then
printf "\nERROR: %s not installed.\n\n" $1
exit 255
fi
}
# MAIN
# check for tools that we depend upon
is_installed tr
is_installed sed
is_installed expr
is_installed curl
is_installed nmap
# check syntax - should have 1 and only 1 parameter on cmdline
if [ $# -ne 1 ]; then
printf "%s %s ( http://blog.nachotech.com/ )\n" $scriptname $scriptversion
printf "Usage: %s {target network specification}\n" $scriptname
printf "TARGET NETWORK SPECIFICATION:\n"
printf " Can pass hostnames, IP addresses, networks, etc.\n"
printf " Ex: server1.company.com, company.com/24, 192.168.0.1/16, 10.0.0-255.1-254\n"
printf "EXAMPLE:\n"
printf " %s 16.32.64.0/22\n" $scriptname
exit 255
fi
iprange=$1
# prepare lookup file for iLO hardware versions
cat > $ilohwvers << EOF
iLO-1 shows hw version ASIC: 2
iLO-2 shows hw version ASIC: 7
iLO-3 shows hw version ASIC: 8
iLO-3 shows hw version ASIC: 9
iLO-4 shows hw version ASIC: 12
iLO-4 shows hw version ASIC: 16
i-iLO shows hw version T0
EOF
#
# scan a range of IP addresses looking for an
# open tcp port 17988 (the iLO virtual media port)
#
printf "Scanning..."
nmap -n -P0 -sS -p 17988 -oG - $iprange | fgrep /open/ | awk '{print $2}' > $iloips
printf "\n\n"
#
# open and read the list of IP addresses one at a time
#
exec 3< $iloips
echo "--------------- ------ -------- ------------ ------------------------- -------------------- -----------------------------"
echo "iLO IP Address iLO HW iLO FW Server S/N Server Model iLO Edition iLO Licence Key"
echo "--------------- ------ -------- ------------ ------------------------- -------------------- -----------------------------"
while read iloip <&3 ; do
ilosfound=$ilosfound+1
#
# attempt to read the xmldata from iLO, no password required
#
curl --proxy "" --fail --silent --max-time 3 http://$iloip/xmldata?item=All > $iloxml
#
# parse out the Server model (server product name)
# from the XML output
#
parseiloxml SPN; servermodel=$parsedstring
parseiloxml SBSN; sernum=$parsedstring
parseiloxml PN; ilotype=$parsedstring
parseiloxml FWRI; ilofirmware=$parsedstring
parseiloxml HWRI; ilohardware=$parsedstring
ilohwver=$(grep "$ilohardware" $ilohwvers|awk '{print $1}')
if [ "$ilohwver" == "" ]; then
ilohwver="N/A"
fi
if [ "$sernum" == "" ]; then
sernum="N/A"
fi
# add start
curl --proxy "" --fail --silent --max-time 3 http://$iloip/xmldata?item=CpqKey > $iloxml
parseiloxml LNAME; ilomodel=$parsedstring
parseiloxml KEY; ilokey=$parsedstring
# add end
printf "%-15s %-6s %-8s %-12s %-25s %-20s %-30s\n" $iloip "$ilohwver" "$ilofirmware" "$sernum" "$servermodel" "$ilomodel" "$ilokey"
done
printf "\n%d iLOs found on network target %s.\n\n" $ilosfound $iprange
rm -f $iloips $iloxml $ilohwvers
exit 0
@echo off
set COUNT=0
:error
set /a COUNT=COUNT+1
echo %COUNT%
if "%COUNT%" == "3" goto errorout
ping -n 1 IPアドレス | find "ms TTL=" > NUL
if ERRORLEVEL 1 goto notrespond
timeout /t 5 > nul
goto error
:notrespond
echo host stopped
goto end
:errorout
echo host not stop
:end
・起動待ちバッチファイル
ping応答があるまで待機する 3回繰り返してもping応答がなければ諦める
@echo off
set COUNT=0
:error
set /a COUNT=COUNT+1
if "%COUNT%" == "3" goto errorout
ping -n 1 IPアドレス | find "ms TTL=" > NUL
if ERRORLEVEL 1 goto error
echo host working
goto end
:errorout
echo host not working
:end
#!/usr/bin/perl
use strict;
use warnings;
use LWP;
use URI::Escape;
use JSON;
use Time::Local;
my $lwpua = LWP::UserAgent->new;
my $url="https://api.iijmio.jp/mobile/d/v1/log/packet/";
my $developerid="<DeveloperID>";
my $usertoken ="<アクセストークン>";
my $lwpreq = HTTP::Request->new(GET => "$url");
$lwpreq->header("X-IIJmio-Developer" => "$developerid");
$lwpreq->header("X-IIJmio-Authorization" => "$usertoken");
my $lwpres= $lwpua->request($lwpreq);
my $data = decode_json($lwpres->content);
for(my $i=0;$i<@{$data->{packetLogInfo}};$i++){
#print $i . ":" . $data->{packetLogInfo}->[$i]->{hddServiceCode} ."\n";
my $hddServiceCode=$data->{packetLogInfo}->[$i]->{hddServiceCode};
for(my $j=0;$j<@{$data->{packetLogInfo}->[$i]->{hdoInfo}};$j++){
#print $i . "-" . $j . ":" . $data->{packetLogInfo}->[$i]->{hdoInfo}->[$j]->{hdoServiceCode} . "\n";
my $hdoServiceCode=$data->{packetLogInfo}->[$i]->{hdoInfo}->[$j]->{hdoServiceCode};
if(! -f "$hdoServiceCode.rrd"){
print "rrdtool create $hdoServiceCode.rrd --start 1384786740 --step 86400 DS:withCoupon:GAUGE:86400:0:U DS:withoutCoupon:GAUGE:86400:0:U RRA:LAST:0.5:1:100000 \n";
system("rrdtool create $hdoServiceCode.rrd --start 1384786740 --step 86400 DS:withCoupon:GAUGE:86400:0:U DS:withoutCoupon:GAUGE:86400:0:U RRA:LAST:0.5:1:100000");
}
for(my $k=0;$k<@{$data->{packetLogInfo}->[$i]->{hdoInfo}->[$j]->{packetLog}};$k++){
#print " " . $data->{packetLogInfo}->[$i]->{hdoInfo}->[$j]->{packetLog}->[$k]->{date} ;
#print ":" . $data->{packetLogInfo}->[$i]->{hdoInfo}->[$j]->{packetLog}->[$k]->{withCoupon} ;
#print ":" . $data->{packetLogInfo}->[$i]->{hdoInfo}->[$j]->{packetLog}->[$k]->{withoutCoupon} ;
#print "\n";
my $d=$data->{packetLogInfo}->[$i]->{hdoInfo}->[$j]->{packetLog}->[$k]->{date};
my $year = substr($d,0,4);
my $mon = substr($d,4,2) - 1;
my $mday = substr($d,6,2);
my $unixtime = timelocal(0,59,23,$mday,$mon,$year);
my $withCoupon=$data->{packetLogInfo}->[$i]->{hdoInfo}->[$j]->{packetLog}->[$k]->{withCoupon};
my $withoutCoupon=$data->{packetLogInfo}->[$i]->{hdoInfo}->[$j]->{packetLog}->[$k]->{withoutCoupon};
print "rrdtool update $hdoServiceCode.rrd $unixtime:$withCoupon:$withoutCoupon \n";
system("rrdtool update $hdoServiceCode.rrd $unixtime:$withCoupon:$withoutCoupon");
}
}
}
これを「get.pl」というファイル名で保存します。
実行すると、「hdo810xxxxx.rrd」というような感じのファイルがSIMカード分作成されます。
なお、手抜きをしているので、2回目以降は、同じ値を入力しようとし、「ERROR: hdo8371xxxx.rrd: illegal attempt to update using time 1387378740 when last update time is 1387378740 (minimum one second step)」みたいなエラーがでてしまいますが、仕様です。
また、rrdtoolは一度登録した情報の更新ができない構造をしているので、日付が変わる直前に実行することを推奨します。