RVCを活用してアラーム情報を取得する

RVCを活用してアラーム情報を取得する

**** 留意事項 *****

こちらのブログの内容はDECN(Dell EMC Community Network)に投稿されたブログの再掲です。

DECNが近い将来に廃止となるためこちらに移行させていただいております。

内容についてはオリジナルの執筆当時のものとなりますので最新ではない場合がありますがご容赦ください。

vSphereのサポートをしていると、お客様によってはお問い合わせ時の情報が不十分で初動が遅れてしまうことが多々あります。

例えばよくある例として、

お客様:「エラーを検知しました」

サポート:「(エラーメッセージが知りたい。。。)」

お客様:「エラーの画面キャプチャ(WebClient)を取得しました」

サポート:「(肝心な部分が切れていて写ってない。。。)」

お客様:「エラーメッセージはこれです。」

サポート:「(できれば英語でほしかった。。。)」

といった感じで、事象を特定するまでに何度かやり取りが発生し、時間がかかってしまうことがあります。

※英語が好まれるのはEscalationや検索の都合によるもの。

vSphere WebClientでは、エラーメッセージのテキストをクリップボードにコピーすることが出来ないため、想像以上に多くのお客様が画面キャプチャを取る、という方法を選びます。

実際には、下図のようにエラーメッセージをコピーすることは可能なのですが、対象のインベントリのMonitor -> All Issueへ移動しなくてはならず、しかもエラーの発生するインベントリは毎回同じではないため、vSphere操作に不慣れなお客様には少々難度が高いです。

1.PNG

そこで前回記事で紹介したRVCを利用したアラーム情報取得スクリプトを考えてみました。

↓↓↓

#!/usr/bin/bash

function retrieveObjInfo() {

  echo ""

  echo "==================================="

  echo $1

  echo "==================================="

  x=\'$1\'

  echo "--------- Alarms of $x ---------------"

  echo $PASS | rvc -c "alarms localhost/$i$2$x" -c "quit" 'administrator@vsphere.local@localhost' 2> /dev/null | tail -n +4

  echo "--------- Config Issue of $x -----------"

  echo $PASS | rvc -c "issues localhost/$i$2$x" -c "quit" 'administrator@vsphere.local@localhost' 2> /dev/null | tail -n +4

}

IFS=$'\n'

echo "vCenter SSO user is administrator@vsphere.local"

read -sp "vCenter SSO Password: " PASS

echo ""

for i in $(echo $PASS | rvc -c "ls localhost" -c "quit" 'administrator@vsphere.local@localhost' 2> /dev/null | grep datacenter | cut -d " " -f 2 | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g");

do

  CLUSTER=""

  echo "Detected Cluster list of DataCenter $i"

  echo "---------------------"

  echo $PASS | rvc -c "ls localhost/$i/computers" -c "quit" 'administrator@vsphere.local@localhost' 2> /dev/null | grep cluster | cut -d " " -f 2 | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g"

  echo "ALL"

  echo "NONE"

  echo "---------------------"

  echo ""

  read -p "Selected Cluster Name (Default:ALL) > " CLUSTER

  if [ "$CLUSTER" = "" ]

  then

    CLUSTER="ALL"

  fi

  for j in $(echo $PASS | rvc -c "ls localhost/$i/computers" -c "quit" 'administrator@vsphere.local@localhost' 2> /dev/null | grep cluster | cut -d " " -f 2 | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g");

  do

    if [ "$CLUSTER" != "ALL" -a "$CLUSTER" != "$j" ]

    then

      break

    fi

    retrieveObjInfo $j "/computers/"

    for k in $(echo $PASS | rvc -c "ls localhost/$i/computers/$j/hosts" -c "quit" 'administrator@vsphere.local@localhost' 2> /dev/null | tail -n +4 | grep host | grep -v localhost | cut -d " " -f 2 | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g");

    do

      retrieveObjInfo $k "/computers/$j/hosts/"

      for n in $(echo $PASS | rvc -c "ls localhost/$i/computers/$j/hosts/$k/vms" -c "quit" 'administrator@vsphere.local@localhost' 2> /dev/null | tail -n +4 | cut -d " " -f 2- | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g" | cut -d ":" -f 1 );

      do

        retrieveObjInfo $n "/computers/$j/hosts/$k/vms/"

      done

    done

  done

  for l in $(echo $PASS | rvc -c "ls localhost/$i/datastores" -c "quit" 'administrator@vsphere.local@localhost' 2> /dev/null | tail -n +4 | cut -d " " -f 2 | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g" | cut -d ":" -f 1);

  do

    retrieveObjInfo $l "/datastores/"

  done

  for m in $(echo $PASS | rvc -c "ls localhost/$i/networks" -c "quit" 'administrator@vsphere.local@localhost' 2> /dev/null | tail -n +4 | cut -d " " -f 2- | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g" | sed -r "s/\ \(vds\)//g" | cut -d ":" -f 1 );

  do

    echo ""

    echo $m

    m=\'$m\'

    echo "--------- Alarms of $x ---------------"

    echo $PASS | rvc -c "alarms localhost/$i/networks/$m" -c "quit" 'administrator@vsphere.local@localhost' 2> /dev/null | tail -n +4

    echo "--------- Config Issue of $x -----------"

    echo $PASS | rvc -c "issues localhost/$i/networks/$m" -c "quit" 'administrator@vsphere.local@localhost' 2> /dev/null | tail -n +4

  done

done

unset IFS

 

コチラのスクリプトはVCSA上で実行することを想定しています。

実行すると、与えられたSSO認証情報を用いてRVC経由でvCenter配下のCluster、ESXi、VM、DataStore、分散仮想スイッチのインベントリで出ているアラート情報をすべて取得してきます。

使い方は簡単です。

1.VCSAにSSHでログイン

2.適当な名前でファイルを作成(例:alarmRetrieve.sh)

3.vi で編集して上記スクリプトを書き込んでSave(※コミュニティからコピーするとHTMLの都合上で余計な改行が入りますが、シェルスクリプトは問題なく動作します。)

4.chmod 777 で実行権限を追加(例: chmod 777 alarmRetrieve.sh)

5.スクリプトを実行(例:./alarmRetrieve.sh)

すべてのインベントリのアラーム情報を取得するため、VM数やNode数が多いと時間がかかりますが、漏れなくすべてのアラームを、英語の原文で取得できます。

アラームの発報時刻がわからないのが非常に残念ですが、vSphereに不慣れなオペレータでも、スクリプトを実行するだけでアラーム情報を入手してサポートに問い合わせることが出来ます。

このスクリプトで入手できるアラート情報があれば、だいたいの場合においてサポートエンジニアにてある程度の業務影響が想定でき、またログ取得対象を絞り込めるため、調査開始の初動がスムーズになります。

アラーム情報だけでなくそれぞれのインベントリの基本情報も合わせて取得する必要がある場合を想定して、上記を少しだけ改良した以下のスクリプトも作成しました。

#!/usr/bin/bash

function retrieveObjInfo() {

  echo ""

  echo "==================================="

  echo $1

  echo "==================================="

  x=\'$1\'

  echo "--------- Summary of $x --------------"

  echo $PASS | rvc -c "show localhost/$i$2$x" -c "quit" 'administrator@vsphere.local@localhost' 2> /dev/null | tail -n +4

  echo "--------- Alarms of $x ---------------"

  echo $PASS | rvc -c "alarms localhost/$i$2$x" -c "quit" 'administrator@vsphere.local@localhost' 2> /dev/null | tail -n +4

  echo "--------- Config Issue of $x -----------"

  echo $PASS | rvc -c "issues localhost/$i$2$x" -c "quit" 'administrator@vsphere.local@localhost' 2> /dev/null | tail -n +4

}

IFS=$'\n'

echo "vCenter SSO user is administrator@vsphere.local"

read -sp "vCenter SSO Password: " PASS

echo ""

for i in $(echo $PASS | rvc -c "ls localhost" -c "quit" 'administrator@vsphere.local@localhost' 2> /dev/null | grep datacenter | cut -d " " -f 2 | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g");

do

  CLUSTER=""

  echo "Detected Cluster list of DataCenter $i"

  echo "---------------------"

  echo $PASS | rvc -c "ls localhost/$i/computers" -c "quit" 'administrator@vsphere.local@localhost' 2> /dev/null | grep cluster | cut -d " " -f 2 | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g"

  echo "ALL"

  echo "NONE"

  echo "---------------------"

  echo ""

  read -p "Selected Cluster Name (Default:ALL) > " CLUSTER

  if [ "$CLUSTER" = "" ]

  then

    CLUSTER="ALL"

  fi

  for j in $(echo $PASS | rvc -c "ls localhost/$i/computers" -c "quit" 'administrator@vsphere.local@localhost' 2> /dev/null | grep cluster | cut -d " " -f 2 | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g");

  do

    if [ "$CLUSTER" != "ALL" -a "$CLUSTER" != "$j" ]

    then

      break

    fi

    retrieveObjInfo $j "/computers/"

    for k in $(echo $PASS | rvc -c "ls localhost/$i/computers/$j/hosts" -c "quit" 'administrator@vsphere.local@localhost' 2> /dev/null | tail -n +4 | grep host | grep -v localhost | cut -d " " -f 2 | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g");

    do

      retrieveObjInfo $k "/computers/$j/hosts/"

      for n in $(echo $PASS | rvc -c "ls localhost/$i/computers/$j/hosts/$k/vms" -c "quit" 'administrator@vsphere.local@localhost' 2> /dev/null | tail -n +4 | cut -d " " -f 2- | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g" | cut -d ":" -f 1 );

      do

        retrieveObjInfo $n "/computers/$j/hosts/$k/vms/"

      done

    done

  done

  for l in $(echo $PASS | rvc -c "ls localhost/$i/datastores" -c "quit" 'administrator@vsphere.local@localhost' 2> /dev/null | tail -n +4 | cut -d " " -f 2 | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g" | cut -d ":" -f 1);

  do

    retrieveObjInfo $l "/datastores/"

  done

  for m in $(echo $PASS | rvc -c "ls localhost/$i/networks" -c "quit" 'administrator@vsphere.local@localhost' 2> /dev/null | tail -n +4 | cut -d " " -f 2- | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g" | sed -r "s/\ \(vds\)//g" | cut -d ":" -f 1 );

  do

    echo ""

    echo $m

    m=\'$m\'

    echo "--------- Summary of $x --------------"

    echo $PASS | rvc -c "vds.show_running_config localhost/$i/networks/$m" -c "quit" 'administrator@vsphere.local@localhost' 2> /dev/null | tail -n +4

    echo "--------- Alarms of $x ---------------"

    echo $PASS | rvc -c "alarms localhost/$i/networks/$m" -c "quit" 'administrator@vsphere.local@localhost' 2> /dev/null | tail -n +4

    echo "--------- Config Issue of $x -----------"

    echo $PASS | rvc -c "issues localhost/$i/networks/$m" -c "quit" 'administrator@vsphere.local@localhost' 2> /dev/null | tail -n +4

  done

done

unset IFS

いかがでしたでしょうか?

障害時にサポートエンジニアによるRemote接続が出来ず、ログ調査がメインとなる環境では、事象の特定に時間がかかり業務影響の判断や調査開始までに時間を擁してしまうことが多々あります。

この記事がそういった時間の短縮にお役に立てれば幸いです。

Version history
Revision #:
1 of 1
Last update:
‎09-25-2019 12:00 AM
Updated by: