ニフクラ ブログ

ニフクラ/FJ Cloud-Vやクラウドの技術について、エンジニアが語るブログです。

ニフクラの各種ログを自動収集して解析してみる

f:id:TechnicalAccountEngineer:20180829114314j:plain

※本記事で利用しているAPIのエンドポイントは 2019年1月31日にクローズ予定の(nifty.com)を利用した 記事になっています。ご利用の際は、下記のリンクでご案内している新しいエンドポイント(nifcloud.com)に置き換えるなどのご対応をお願いいたします。
クラウド API(エンドポイント) | ニフクラ

こんにちは、ニフクラテクニカルアカウントチームです。
システムの構築を行う際に、各種ログを保管する、解析する仕組みが必要になることがあると思います。
たとえば、外部からのアクセスログや内部の操作ログを情報漏洩防止などセキュリティ目的で利用したり、システムの運用・監視においても自動化を進める上で各種ログの保管・解析は重要になるでしょう。

今回は、ニフクラで利用できるニフクラ ファイアウォールで通信を拒否したログ、コントロールパネル操作のアクティビティログなどをニフクラのコマンドラインツール で自動収集する手順をご説明します。データ自体はオブジェクトストレージに格納しています。
且つ収集したログをSplunkで可視化して解析できるというところまで確認しています。

環境構築の詳細まで記載しているため長くなっていますが、参考にしていただけましたら幸いです。

前提条件

本ブログ記事は、以下の前提知識がある方を想定しています。

  • ニフクラの基本的なコントロールパネルの操作、サービスを利用する知識
    (サーバー作成、ネットワーク構築など)
  • 基本的なサーバーOSを構築する知識

構成イメージ

今回の検証での構成イメージを記載します。
※各リソースのアクセス制限に関しては、ニフクラのファイアウォール等を用いて適切に設定の上実施しています。

f:id:TechnicalAccountEngineer:20180829113510j:plain

・補足
オブジェクトストレージをSplunkサーバー(CentOS7.1)から「goofys」を利用してマウントしています。
せっかくなのでオブジェクトストレージをセキュアに利用できる専有エンドポイント経由で試行しています。
・Splunk バージョン:Ver 7.1.0
・goofys バージョン:Ver 0.19.0

環境構築

実際に環境構築を行った手順等を記載しています。ご参考にしてみてください。

サーバーの作成

ニフクラ上でSplunkを導入するサーバー(Splunkサーバー)とファイアウォールログの収集対象とするサーバー(Server1)を作成します。
両サーバーとも今回は CentOS7.1にて作成しています。
サーバー作成の詳細は割愛します。サーバーの作成を参照してください。

専有エンドポイントの作成&オブジェクトストレージのバケット作成

ニフクラ上で専有エンドポイントと、オブジェクトストレージのバケット作成を行います。 作成方法はクラウドヘルプ(専有エンドポイント)クラウド ヘルプ(ストレージ)を参照してください。

今回は以下で作成しています。

  • 専有エンドポイント名:kensyoep
  • オブジェクトストレージバケット名:2018q-kensyo-bucket

事前準備

Splunkサーバーに対して事前準備を実施します。

  • ニフクラコマンドラインツールの配置
    コマンドラインツールをダウンロードします。
$ cd [ダウンロード先ディレクトリ]
$ wget https://cloud.nifty.com/api/sdk/NIFTY_Cloud_api-tools.zip
$ ls -l NIFTY_Cloud_api-tools.zip

コマンドラインツールを「/usr/local/src」に解凍します。

$ cd /usr/local/src ;pwd
$ unzip [ダウンロード先ディレクトリ]/NIFTY_Cloud_api-tools.zip

コマンドラインツールに実行権限を付与します。

$ chmod 755 NIFTY_Cloud_api-tools/bin/*
$ ls -l NIFTY_Cloud_api-tools/bin

  • 続いてJAVAをインストールします。
    JAVAのインストール。(ここではjava-1.8.0をインストールします)
$yum install java-1.8.0-openjdk.x86_64
$java -version
 ⇒versionが「"1.8.0_171"」以上であることを確認します。

  • 次にオブジェクトストレージをマウントするための「goofys」をインストールします。
    必要な前提パッケージをまずインストール
$ yum install golang fuse -y

goofysをインストールします。

$ export GOPATH=$HOME/go
$ go get github.com/kahing/goofys
$ go install github.com/kahing/goofys
$ $GOPATH/bin/goofys -h

aws cliをインストールします。

$ yum install -y epel-release
$ yum update -y
$ yum install -y awscli

ニフクラファイアウォールログ収集スクリプトの作成

Splunkサーバーを対象に作業を行います。

  • ファイアウォールログ収集スクリプトの作成
    FWログ収集スクリプト配置先ディレクトリの作成
$ mkdir -p [FWログ収集スクリプト配置先ディレクトリ]

メインシェルの作成

$ cd [FWログ収集スクリプト配置先ディレクトリ] ;pwd
$ vi FWlog_collect.sh
※ソースコード及び環境ごとの修正箇所は後述の「ファイアウォールログ収集スクリプト_ソースコード」の「FWlog_collect.sh」を参照
$ cat FWlog_collect.sh

confファイルの作成

$ mkdir conf
$ ls -ld conf
$ cd conf ;pwd
$ vi common.conf
※ソースコード及び環境ごとの修正箇所は後述の「ファイアウォールログ収集スクリプト_ソースコード」の「common.conf」を参照
$ cat common.conf

fw_groupファイルを作成します。
※ログを収集するファイアウォールグループ名をファイル中に記載します。  記載は今回のものとなるので、実態に合わせて記載してください。

$ vi east-1_fw_group
kensyoBenchFW11
kensyoBenchFW14
kensyoFW01
kensyoFW02

※east-1 リージョン以外のリストファイルを作成する場合はそれぞれファイル名を変更してファイルを作成してください。
 ・east-2:vi east-2_fw_group
 ・east-3:vi east-3_fw_group
 ・east-4:vi east-4_fw_group
 ・west-1:vi west-1_fw_group

「SecretAccessKey」ファイルを作成します。
※秘匿情報のため、サーバー上に平文で保存しないようbase64でエンコードしています

$ echo <"実行環境のシークレットアクセスキーを記載"> | base64 > SecretAccessKey

「Splunk_user」ファイルを作成します。
※秘匿情報のため、サーバー上に平文で保存しないようbase64でエンコードしています

$ echo <"Splunkユーザ名を記載"> | base64 > Splunk_user

「Splunk_pass」ファイルを作成します。
※秘匿情報のため、サーバー上に平文で保存しないようbase64でエンコードしています

$ echo <"Splunkユーザのパスワードを記載"> | base64 > Splunk_pass

  • 実行権限の付与
    メインシェルに実行権限を付与します。
$ cd ../ ;pwd
$ chmod 740 FWlog_collect.sh

  • スクリプトの手動実行(動作確認のため実施)
    FWlog_collect.shを手動実行します。
$ sh -x FWlog_collect.sh

  • cron設定(スクリプトを自動実行させる場合に実施)
    cronを編集します。
$ crontab -e

夜間の0時15分にスクリプトを実行させる場合

15 0 * * * [FWログ収集スクリプト配置先ディレクトリ]/FWlog_collect.sh > /dev/null 2>&1

アクティビティログ収集スクリプト作成

Splunkサーバーを対象に作業を行います。

  • アクティビティログ収集スクリプトの作成
    アクティビティログ収集スクリプト配置先ディレクトリの作成
$ mkdir -p [アクティビティログ収集スクリプト配置先ディレクトリ]

メインシェルの作成

$ cd [アクティビティログ収集スクリプト配置先ディレクトリ] ;pwd
$ vi Actlog_collect.sh
※ソースコード及び環境ごとの修正箇所は後述の「アクティビティログ収集スクリプト_ソースコード」の「Actlog_collect.sh」を参照
$ cat Actlog_collect.sh

confファイルの作成

$ mkdir conf
$ ls -ld conf
$ cd conf ;pwd
$ vi common.conf
※ソースコード及び環境ごとの修正箇所は後述の「アクティビティログ収集スクリプト_ソースコード」の「common.conf」を参照
$ cat common.conf

「SecretAccessKey」ファイルを作成します。
※秘匿情報のため、サーバー上に平文で保存しないようbase64でエンコードしています

$ echo <"実行環境のシークレットアクセスキーを記載"> | base64 > SecretAccessKey

「Splunk_user」ファイルを作成します。
※秘匿情報のため、サーバー上に平文で保存しないようbase64でエンコードしています

$ echo <"Splunkユーザ名を記載"> | base64 > Splunk_user

「Splunk_pass」ファイルを作成します。
※秘匿情報のため、サーバー上に平文で保存しないようbase64でエンコードしています

$ echo <"Splunkユーザのパスワードを記載"> | base64 > Splunk_pass

  • 実行権限の付与
    メインシェルに実行権限を付与します。
$ cd ../ ;pwd
$ chmod 740 Actlog_collect.sh

  • スクリプトの手動実行(動作確認のため実施) Actlog_collect.shを手動実行します。
$ sh -x Actlog_collect.sh

  • cron設定(スクリプトを自動実行させる場合に実施) cronを編集します。
$ crontab -e

夜間の0時10分にスクリプトを実行させる場合

10 0 * * * [アクティビティログ収集スクリプト配置先ディレクトリ]/Actlog_collect.sh > /dev/null 2>&1

パフォーマンスチャート収集スクリプトの作成

Splunkサーバーを対象に作業を行います。

  • パフォーマンスチャート収集スクリプトの作成
    パフォーマンスチャート収集スクリプト配置先ディレクトリの作成
$ mkdir -p [パフォーマンスチャート収集スクリプト配置先ディレクトリ]

メインシェルの作成

$ cd [パフォーマンスチャート収集スクリプト配置先ディレクトリ] ;pwd
$ vi Perfchart_collect.sh
※ソースコード及び環境ごとの修正箇所は後述の「パフォーマンスチャート収集スクリプト_ソースコード」の「Perfchart_collect.sh」を参照
$ cat Perfchart_collect.sh

confファイルの作成

$ mkdir conf
$ ls -ld conf
$ cd conf ;pwd
$ vi common.conf
※ソースコード及び環境ごとの修正箇所は後述の「パフォーマンスチャート収集スクリプト_ソースコード」の「common.conf」を参照
$ cat common.conf

「SecretAccessKey」ファイルを作成します。
※秘匿情報のため、サーバー上に平文で保存しないようbase64でエンコードしています

$ echo <"実行環境のシークレットアクセスキーを記載"> | base64 > SecretAccessKey

「Splunk_user」ファイルを作成します。
※秘匿情報のため、サーバー上に平文で保存しないようbase64でエンコードしています

$ echo <"Splunkユーザ名を記載"> | base64 > Splunk_user

「Splunk_pass」ファイルを作成します。
※秘匿情報のため、サーバー上に平文で保存しないようbase64でエンコードしています

$ echo <"Splunkユーザのパスワードを記載"> | base64 > Splunk_pass

  • 実行権限の付与
    メインシェルに実行権限を付与します。
$ cd ../ ;pwd
$ chmod 740 Perfchart_collect.sh

  • スクリプトの手動実行(動作確認のため実施) Perfchart_collect.shを手動実行します。
$ sh -x Perfchart_collect.sh

  • cron設定(スクリプトを自動実行させる場合に実施) cronを編集します。
$ crontab -e

夜間の0時10分にスクリプトを実行させる場合

10 0 * * * [パフォーマンスチャート収集スクリプト配置先ディレクトリ]/Perfchart_collect.sh > /dev/null 2>&1

Splunk導入

SplunkサーバーにSplunkを導入します。

  • Splunkのインストール
    ・前提条件
     インターネットにアクセスが可能なこと
    ・ダウンロード
     公式サイトからFree版のSplunk Enterpriseをダウンロードします。
     ダウンロード時にアカウント登録が必要となります。参考URL
    ・インストール
     任意の場所にダウンロードしたモジュールを配置します。
     配置した場所に移動し、以下のコマンドでインストールします。
$ rpm -ivh splunk-7.1.0-2e75b3406c5b-linux-2.6-x86_64.rpm

  • Splunkの初回起動
    ・Splunk初回起動時にライセンスに同意してパスワードを設定します。
$ /opt/splunk/bin/splunk start

下記の赤字箇所を入力します。

<省略>
Do you agree with this license? [y/n]: y    ←yで同意
<省略>
Password must contain at least:
   * 8 total printable ASCII character(s). 
Please enter a new password:xxxxxxx      ←パスワード設定
Please confirm new password:xxxxxxx      ←設定したパスワードの再入力
Empty passwords are not allowed.
First-time-run has not finished.  Ignore this error when previewing migration - exiting.

  • Splunk自動起動設定
    Splunkの自動起動をonにします。
$ /opt/splunk/bin/splunk enable boot-start
$ chkconfig --list splunk
Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

splunk 0:off 1:off 2:on 3:on 4:on 5:on 6:off

  • 作業PCのブラウザからSplunkにログイン
    下記アドレスにアクセスしてログインします。
    http://<SplunkサーバーのグローバルIP>:8000/ja-JP/
     ID:admin
     PW:初回起動時に設定したパスワード

f:id:TechnicalAccountEngineer:20180904151954j:plain

f:id:TechnicalAccountEngineer:20180904152014j:plain

ログ取り込み

Splunkサーバーにて実際にログの取り込みを実施します。

  • データ取り込み
    ① Splunkコンソールにログインします。
    ② 「Search & Reporting」を押下します。
    ③ タブの「設定」を押下します。
    ④ 「データ入力」を押下します。
    ⑤ 「ファイルとディレクトリ」を押下します。
    ⑥ 「新しいローカルファイルとディレクトリ」を押下します。
    ⑦ 「参照」を押下します。
    ⑧ オブジェクトストレージをマウントしているディレクトリを選択します。
     ※ここでは「ObjectStorage」を選択します。
    ⑨ 「次へ」を押下します。
    ⑩ 「確認」を押下します。
    ⑪ 「実行」を押下します。
    ⑫ 「ファイル入力が正常に作成されました。」と表示される事を確認します。
f:id:TechnicalAccountEngineer:20180912140905j:plain f:id:TechnicalAccountEngineer:20180912140908j:plain f:id:TechnicalAccountEngineer:20180912140910j:plain
f:id:TechnicalAccountEngineer:20180912140913j:plain f:id:TechnicalAccountEngineer:20180912140915j:plain f:id:TechnicalAccountEngineer:20180912140917j:plain
f:id:TechnicalAccountEngineer:20180912140920j:plain f:id:TechnicalAccountEngineer:20180912140851j:plain f:id:TechnicalAccountEngineer:20180912140854j:plain
f:id:TechnicalAccountEngineer:20180912140857j:plain f:id:TechnicalAccountEngineer:20180912140901j:plain f:id:TechnicalAccountEngineer:20180912140903j:plain

ログ解析

Splunkコンソールにて実際にログを確認します。
本手順では、主にeast-1のファイアウォールグループ(kensyoFW01)に対して拒否された通信ログを例として実施しています。

  • サーチコマンド
    収集した各種ログを解析する際に今回利用したものを以下に記載しておきます。

【ファイアウォールログ】
[ログ確認] east-1のファイアウォールグループ(kensyoFW01)に対して、拒否された通信ログを抽出する

source ="/ObjectStorage/FWlog/east-1/kensyoFW01/*"

[ログ解析] 拒否した送信元IPアドレスの時間別件数 TOP10 (kensyoFW01)

source ="/ObjectStorage/FWlog/east-1/kensyoFW01/*"| timechart count by field3 limit=10

[ログ解析] 拒否した送信元IPアドレスのランキング TOP10 (kensyoFW01)

source ="/ObjectStorage/FWlog/east-1/kensyoFW01/*"| top limit=10 field3

【アクティビティログ】
[ログ確認] 「ログイン」に関するログを抽出する

source ="/ObjectStorage/Actlog/*" "ログイン"

[ログ解析] ログイン試行を実施した送信元IPアドレスの時間別件

source ="/ObjectStorage/Actlog/*" "ログイン"| timechart count by field2 limit=10

[ログ解析] east-1で操作が行われた機能に関するランキング TOP10

source ="/ObjectStorage/Actlog/east-1/*"| top limit=10 field3

[ログ解析] east-1で操作が行われた機能に関する時間別件数 (アカウント名を指定)

source ="/ObjectStorage/Actlog/east-1/*" <アカウント名> | timechart  count by field3 limit=10

【パフォーマンスログ】
[ログ確認] east-1のサーバー(20181QkensyoSK)に対して、パフォーマンスログ(CPU)を抽出する

source ="/ObjectStorage/PerfChart/east-1/20180QkensyoSK/*" "cpu"

[ログ解析] east-1のサーバー(20181QkensyoSK)に対して、CPU使用率を表示する

source ="/ObjectStorage/PerfChart/east-1/20181QkensyoSK/*" "cpu" | timechart max(field8)

  • ログの確認
    ① 「Search & Reporting」を押下します。
    ② サーチ項目に上記の「サーチコマンド」-「ファイアウォールログ」-「ログ確認」のコマンドを入力し「検索アイコン」を押下します。
    ③ 「イベント」の列にログが表示されたことを確認します。
f:id:TechnicalAccountEngineer:20180913111349j:plain f:id:TechnicalAccountEngineer:20180913111412j:plain f:id:TechnicalAccountEngineer:20180913111441j:plain
  • ログの解析 ① サーチ項目に上記の「サーチコマンド」-「ファイアウォールログ」-「ログ解析」のコマンドを入力し「検索アイコン」を押下します。
    ② 画面に拒否した送信元IPアドレスの情報が表示されたことを確認し、「視覚エフェクト」を押下します。
    ③ 視覚エフェクト(グラフ)が表示された事を確認します。
f:id:TechnicalAccountEngineer:20180913112739j:plain f:id:TechnicalAccountEngineer:20180913112744j:plain f:id:TechnicalAccountEngineer:20180913112750j:plain
  • ログのレポートを作成
    ① 「名前を付けて保存」を押下します。
    ② プルダウンから「レポート」を押下します。
    ③ 「タイトル」を任意の名を入力し「保存」を押下します。
    ④ 「レポートが作成されました」と表示されることを確認し「表示」を押下します。
    ⑤ 「レポート」タブを押下します。
    ⑥ タイトルに「③」で設定した文字列が表示されることを確認し、作成したレポート名を押下します。
    ⑦ 設定通りに表示されることを確認します。
f:id:TechnicalAccountEngineer:20180914145520j:plain f:id:TechnicalAccountEngineer:20180914145634j:plain f:id:TechnicalAccountEngineer:20180914145111j:plain
f:id:TechnicalAccountEngineer:20180914145059j:plain f:id:TechnicalAccountEngineer:20180914145045j:plain f:id:TechnicalAccountEngineer:20180914145040j:plain
f:id:TechnicalAccountEngineer:20180914144957j:plain
  • ダッシュボードへの保存
    ① 作成したレポートを選択し、「ダッシュボードに追加」を押下します。
    ② ダッシュボードIDに任意の文字列を入力して「保存」を押下します。
f:id:TechnicalAccountEngineer:20180914152211j:plain f:id:TechnicalAccountEngineer:20180914152217j:plain
  • ホーム・ダッシュボードへの設定
    ① 対象のダッシュボードを選択後、「…」-「ホーム・ダッシュボードとして設定」を押下します。
    ② Splunkコンソールのホーム画面に選択したダッシュボードが表示されることを確認します。
f:id:TechnicalAccountEngineer:20180918174321j:plain f:id:TechnicalAccountEngineer:20180914155235j:plain

ログをいろんな視点からみてみる

ここまでの操作で各種ログ等の解析が可能になりました。 ここからは今までの操作を用いて各種ログをいろいろと解析してみたのでご参考までに記載しておきます。

ニフクラファイアウォールログ

拒否した送信元IPアドレスの時間別件数 TOP10

f:id:TechnicalAccountEngineer:20180914155103j:plain

拒否した送信元IPアドレスのランキング TOP10 (期間指定)

f:id:TechnicalAccountEngineer:20180914155124j:plain

アクティビティログ

east-1で操作が行われた機能の割合

f:id:TechnicalAccountEngineer:20180914155133j:plain

east-1で操作が行われた機能に関する時間別件数(マルチアカウントごと)

f:id:TechnicalAccountEngineer:20180914155144j:plain

コントロールパネル

ログイン試行を実施した送信元IPアドレスの時間別件数

f:id:TechnicalAccountEngineer:20180914155151j:plain

パフォーマンスチャート

2台の仮想サーバーのCPU使用率を並べて表示

f:id:TechnicalAccountEngineer:20180914155204j:plain

各スクリプトソースコード

今回収集した各種ログの収集スクリプトのソースコードを以下に記載しておきます。 実装される際のご参考にしてください。

ファイアウォールログ収集スクリプト_ソースコード

  • FWlog_collect.sh
$!/bin/bash

$ Common function Reading
. /var/tmp/FWlog_collect/conf/common.conf  ⇒スクリプトの配置先ディレクトリを指定

$ ObjectStorage mounting
if ! mountpoint -q /ObjectStorage ;then
    ${GOOFYS_CMDPATH} --endpoint ${OBST_ENDPOINT} ${OBST_BUCKETNAME} ${OBST_MOUNTPOINT}
fi

$$$ east-1

while read FwGroupName ;do
    $ If the firewall group name is comment out or empty, the line is skips
    test -z "${FwGroupName}" && continue
    echo ${FwGroupName} | grep '^$.*' > /dev/null && continue

    $ Directory creation
    if ! [ -e ${EAST_1_LOG_DIR}/${FwGroupName} ];then
    mkdir -p ${EAST_1_LOG_DIR}/${FwGroupName}
    chmod 755 ${EAST_1_LOG_DIR}/${FwGroupName}
    chown root:root ${EAST_1_LOG_DIR}/${FwGroupName}
    fi

    $ endpoint setting
    export NIFTY_CLOUD_URL=https://computing.jp-east-1.api.cloud.nifty.com/api/

    $ CLI execution
    nifty-describe-security-activities ${FwGroupName} -d ${COLLECT_DATE} -a | \
    grep -v '^\s*GROUP' | grep -v '^\s*LOG' \
    > ${EAST_1_LOG_DIR}/${FwGroupName}/${FwGroupName}_${COLLECT_DATE}.log
done < ${SHELL_CNF_DIR}/${EAST_1_FW_LIST}

$$$ east-2

while read FwGroupName ;do
    $ If the firewall group name is comment out or empty, the line is skips
    test -z "${FwGroupName}" && continue
    echo ${FwGroupName} | grep '^$.*' > /dev/null && continue

    $ Directory creation
    if ! [ -e ${EAST_2_LOG_DIR}/${FwGroupName} ];then
    mkdir -p ${EAST_2_LOG_DIR}/${FwGroupName}
    chmod 755 ${EAST_2_LOG_DIR}/${FwGroupName}
    chown root:root ${EAST_2_LOG_DIR}/${FwGroupName}
    fi

    $ endpoint setting
    export NIFTY_CLOUD_URL=https://computing.jp-east-2.api.cloud.nifty.com/api/

    $ CLI execution
    nifty-describe-security-activities ${FwGroupName} -d ${COLLECT_DATE} -a | \
    grep -v '^\s*GROUP' | grep -v '^\s*LOG' \
    > ${EAST_2_LOG_DIR}/${FwGroupName}/${FwGroupName}_${COLLECT_DATE}.log
done < ${SHELL_CNF_DIR}/${EAST_2_FW_LIST}

$$$ east-3

while read FwGroupName ;do
    $ If the firewall group name is comment out or empty, the line is skips
    test -z "${FwGroupName}" && continue
    echo ${FwGroupName} | grep '^$.*' > /dev/null && continue

    $ Directory creation
    if ! [ -e ${EAST_3_LOG_DIR}/${FwGroupName} ];then
    mkdir -p ${EAST_3_LOG_DIR}/${FwGroupName}
    chmod 755 ${EAST_3_LOG_DIR}/${FwGroupName}
    chown root:root ${EAST_3_LOG_DIR}/${FwGroupName}
    fi

    $ endpoint setting
    export NIFTY_CLOUD_URL=https://computing.jp-east-3.api.cloud.nifty.com/api/

    $ CLI execution
    nifty-describe-security-activities ${FwGroupName} -d ${COLLECT_DATE} -a | \
    grep -v '^\s*GROUP' | grep -v '^\s*LOG' \
    > ${EAST_3_LOG_DIR}/${FwGroupName}/${FwGroupName}_${COLLECT_DATE}.log
done < ${SHELL_CNF_DIR}/${EAST_3_FW_LIST}

$$$ jp-east-4

while read FwGroupName ;do
    $ If the firewall group name is comment out or empty, the line is skips
    test -z "${FwGroupName}" && continue
    echo ${FwGroupName} | grep '^$.*' > /dev/null && continue

    $ Directory creation
    if ! [ -e ${JP_EAST_4_LOG_DIR}/${FwGroupName} ];then
    mkdir -p ${JP_EAST_4_LOG_DIR}/${FwGroupName}
    chmod 755 ${JP_EAST_4_LOG_DIR}/${FwGroupName}
    chown root:root ${JP_EAST_4_LOG_DIR}/${FwGroupName}
    fi

    $ endpoint setting
    export NIFTY_CLOUD_URL=https://computing.jp-east-4.api.cloud.nifty.com/api/

    $ CLI execution
    nifty-describe-security-activities ${FwGroupName} -d ${COLLECT_DATE} -a | \
    grep -v '^\s*GROUP' | grep -v '^\s*LOG' \
    > ${JP_EAST_4_LOG_DIR}/${FwGroupName}/${FwGroupName}_${COLLECT_DATE}.log
done < ${SHELL_CNF_DIR}/${JP_EAST_4_FW_LIST}

$$$ west-1

while read FwGroupName ;do
    $ If the firewall group name is comment out or empty, the line is skips
    test -z "${FwGroupName}" && continue
    echo ${FwGroupName} | grep '^$.*' > /dev/null && continue

    $ Directory creation
    if ! [ -e ${WEST_1_LOG_DIR}/${FwGroupName} ];then
    mkdir -p ${WEST_1_LOG_DIR}/${FwGroupName}
    chmod 755 ${WEST_1_LOG_DIR}/${FwGroupName}
    chown root:root ${WEST_1_LOG_DIR}/${FwGroupName}
    fi

    $ endpoint setting
    export NIFTY_CLOUD_URL=https://computing.jp-west-1.api.cloud.nifty.com/api/

    $ CLI execution
    nifty-describe-security-activities ${FwGroupName} -d ${COLLECT_DATE} -a | \
    grep -v '^\s*GROUP' | grep -v '^\s*LOG' \
    > ${WEST_1_LOG_DIR}/${FwGroupName}/${FwGroupName}_${COLLECT_DATE}.log
done < ${SHELL_CNF_DIR}/${WEST_1_FW_LIST}

$$$ us-east-1

while read FwGroupName ;do
    $ If the firewall group name is comment out or empty, the line is skips
    test -z "${FwGroupName}" && continue
    echo ${FwGroupName} | grep '^$.*' > /dev/null && continue

    $ Directory creation
    if ! [ -e ${US_EAST_1_LOG_DIR}/${FwGroupName} ];then
    mkdir -p ${US_EAST_1_LOG_DIR}/${FwGroupName}
    chmod 755 ${US_EAST_1_LOG_DIR}/${FwGroupName}
    chown root:root ${US_EAST_1_LOG_DIR}/${FwGroupName}
    fi

    $ endpoint setting
    export NIFTY_CLOUD_URL=https://computing.us-east-1.api.cloud.nifty.com/api/

    $ CLI execution
    nifty-describe-security-activities ${FwGroupName} -d ${COLLECT_DATE} -a | \
    grep -v '^\s*GROUP' | grep -v '^\s*LOG' \
    > ${US_EAST_1_LOG_DIR}/${FwGroupName}/${FwGroupName}_${COLLECT_DATE}.log
done < ${SHELL_CNF_DIR}/${US_EAST_1_FW_LIST}

$ splunk monitor reload
expect -c "
spawn /opt/splunk/bin/splunk reload monitor
expect \"Splunk username:\"
send -- \"${SPLUNK_USER}\n\"
expect \"Password:\"
send -- \"${SPLUNK_PASS}\n\"
expect \"Monitor inputs reloaded\"
send -- \"exit\n\"
"
sleep 1m

$ ObjectStorage unmounting
umount ${OBST_MOUNTPOINT}
if [ "$?" -eq 0 ]
then
  exit 0
else
  exit 1
fi

  • common.conf
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$ Common definition
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
export SHELL_CNF_DIR=/var/tmp/FWlog_collect/conf  ⇒「conf」ディレクトリのパスを指定
export NIFTY_ACCESS_KEY_ID=XXXXXXXXXXXXXXXXXX  ⇒実行環境のアクセスキーを指定
export GOOFYS_CMDPATH=/root/go/bin/goofys  ⇒「goofys」コマンドのフルパスを指定
export OBST_ENDPOINT=http://xxxxxxxxxx  ⇒オブジェクトストレージのエンドポイントを指定
export OBST_BUCKETNAME=20181q-kensyo-bucket  ⇒オブジェクトストレージのバケット名を指定
export OBST_MOUNTPOINT=/ObjectStorage  ⇒オブジェクトストレージのマウントポイントを指定
export NIFTY_CLOUD_HOME=/usr/local/src/NIFTY_Cloud_api-tools
export NIFTY_SECRET_KEY=`base64 -d ${SHELL_CNF_DIR}/SecretAccessKey`
export SPLUNK_USER=`base64 -d ${SHELL_CNF_DIR}/Splunk_user`
export SPLUNK_PASS=`base64 -d ${SHELL_CNF_DIR}/Splunk_pass`
export JAVA_HOME=/usr/lib/jvm/jre
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:${JAVA_HOME}/bin:${NIFTY_CLOUD_HOME}/bin
export COLLECT_DATE=`date +"%Y%m%d" --date "1 day ago"`
export AWS_ACCESS_KEY_ID=${NIFTY_ACCESS_KEY_ID}
export AWS_SECRET_ACCESS_KEY=${NIFTY_SECRET_KEY}
export AWS_DEFAULT_OUTPUT=text

$ east-1
EAST_1_LOG_DIR=${OBST_MOUNTPOINT}/FWlog/east-1
EAST_1_FW_LIST=east-1_fw_group

$ east-2
EAST_2_LOG_DIR=${OBST_MOUNTPOINT}/FWlog/east-2
EAST_2_FW_LIST=east-2_fw_group

$ east-3
EAST_3_LOG_DIR=${OBST_MOUNTPOINT}/FWlog/east-3
EAST_3_FW_LIST=east-3_fw_group

$ jp-east-4
JP_EAST_4_LOG_DIR=${OBST_MOUNTPOINT}/FWlog/east-4
JP_EAST_4_FW_LIST=jp-east-4_fw_group

$ west-1
WEST_1_LOG_DIR=${OBST_MOUNTPOINT}/FWlog/west-1
WEST_1_FW_LIST=west-1_fw_group

$ us-east-1
US_EAST_1_LOG_DIR=${OBST_MOUNTPOINT}/FWlog/us-east-1
US_EAST_1_FW_LIST=us-east-1_fw_group

アクティビティログ収集スクリプト_ソースコード

  • Actlog_collect.sh
$!/bin/bash

$ Common function Reading
. /var/tmp/Actlog_collect/conf/common.conf  ⇒スクリプトの配置先ディレクトリを指定

$ ObjectStorage mounting
if ! mountpoint -q /ObjectStorage ;then
    ${GOOFYS_CMDPATH} --endpoint ${OBST_ENDPOINT} ${OBST_BUCKETNAME} ${OBST_MOUNTPOINT}
fi

$$$ east-1

$ Directory creation
if ! [ -e ${EAST_1_ACTLOG_DIR} ];then
mkdir -p ${EAST_1_ACTLOG_DIR}
chmod 755 ${EAST_1_ACTLOG_DIR}
chown root:root ${EAST_1_ACTLOG_DIR}
fi

$ endpoint setting
export NIFTY_CLOUD_URL=https://computing.jp-east-1.api.cloud.nifty.com/api/

$ CLI execution
nifty-describe-user-activities | grep `date +"%Y-%m-%d" --date "1 day ago"` \
> ${EAST_1_ACTLOG_DIR}/east-1_tmp.log
sed -E 's/ +/ /g' ${EAST_1_ACTLOG_DIR}/east-1_tmp.log \
> ${EAST_1_ACTLOG_DIR}/east-1_${COLLECT_DATE}.log
rm ${EAST_1_ACTLOG_DIR}/east-1_tmp.log

$$$ east-2

$ Directory creation
if ! [ -e ${EAST_2_ACTLOG_DIR} ];then
mkdir -p ${EAST_2_ACTLOG_DIR}
chmod 755 ${EAST_2_ACTLOG_DIR}
chown root:root ${EAST_2_ACTLOG_DIR}
fi

$ endpoint setting
export NIFTY_CLOUD_URL=https://computing.jp-east-2.api.cloud.nifty.com/api/

$ CLI execution
nifty-describe-user-activities | grep `date +"%Y-%m-%d" --date "1 day ago"` \
> ${EAST_2_ACTLOG_DIR}/east-2_tmp.log
sed -E 's/ +/ /g' ${EAST_2_ACTLOG_DIR}/east-2_tmp.log \
> ${EAST_2_ACTLOG_DIR}/east-2_${COLLECT_DATE}.log
rm ${EAST_2_ACTLOG_DIR}/east-2_tmp.log

$$$ east-3

$ Directory creation
if ! [ -e ${EAST_3_ACTLOG_DIR} ];then
mkdir -p ${EAST_3_ACTLOG_DIR}
chmod 755 ${EAST_3_ACTLOG_DIR}
chown root:root ${EAST_3_ACTLOG_DIR}
fi

$ endpoint setting
export NIFTY_CLOUD_URL=https://computing.jp-east-3.api.cloud.nifty.com/api/

$ CLI execution
nifty-describe-user-activities | grep `date +"%Y-%m-%d" --date "1 day ago"` \
> ${EAST_3_ACTLOG_DIR}/east-3_tmp.log
sed -E 's/ +/ /g' ${EAST_3_ACTLOG_DIR}/east-3_tmp.log \
> ${EAST_3_ACTLOG_DIR}/east-3_${COLLECT_DATE}.log
rm ${EAST_3_ACTLOG_DIR}/east-3_tmp.log

$$$ jp-east-4

$ Directory creation
if ! [ -e ${JP_EAST_4_ACTLOG_DIR} ];then
mkdir -p ${JP_EAST_4_ACTLOG_DIR}
chmod 755 ${JP_EAST_4_ACTLOG_DIR}
chown root:root ${JP_EAST_4_ACTLOG_DIR}
fi

$ endpoint setting
export NIFTY_CLOUD_URL=https://computing.jp-east-4.api.cloud.nifty.com/api/

$ CLI execution
nifty-describe-user-activities | grep `date +"%Y-%m-%d" --date "1 day ago"` \
> ${JP_EAST_4_ACTLOG_DIR}/jp-east-4_tmp.log
sed -E 's/ +/ /g' ${JP_EAST_4_ACTLOG_DIR}/jp-east-4_tmp.log \
> ${JP_EAST_4_ACTLOG_DIR}/jp-east-4_${COLLECT_DATE}.log
rm ${JP_EAST_4_ACTLOG_DIR}/jp-east-4_tmp.log

$$$ west-1

$ Directory creation
if ! [ -e ${WEST_1_ACTLOG_DIR} ];then
mkdir -p ${WEST_1_ACTLOG_DIR}
chmod 755 ${WEST_1_ACTLOG_DIR}
chown root:root ${WEST_1_ACTLOG_DIR}
fi

$ endpoint setting
export NIFTY_CLOUD_URL=https://computing.jp-west-1.api.cloud.nifty.com/api/

$ CLI execution
nifty-describe-user-activities | grep `date +"%Y-%m-%d" --date "1 day ago"` \
> ${WEST_1_ACTLOG_DIR}/west-1_tmp.log
sed -E 's/ +/ /g' ${WEST_1_ACTLOG_DIR}/west-1_tmp.log \
> ${WEST_1_ACTLOG_DIR}/west-1_${COLLECT_DATE}.log
rm ${WEST_1_ACTLOG_DIR}/west-1_tmp.log

$$$ us-east-1

$ Directory creation
if ! [ -e ${US_EAST_1_ACTLOG_DIR} ];then
mkdir -p ${US_EAST_1_ACTLOG_DIR}
chmod 755 ${US_EAST_1_ACTLOG_DIR}
chown root:root ${US_EAST_1_ACTLOG_DIR}
fi

$ endpoint setting
export NIFTY_CLOUD_URL=https://computing.us-east-1.api.cloud.nifty.com/api/

$ CLI execution
nifty-describe-user-activities | grep `date +"%Y-%m-%d" --date "1 day ago"` \
> ${US_EAST_1_ACTLOG_DIR}/us-east-1_tmp.log
sed -E 's/ +/ /g' ${US_EAST_1_ACTLOG_DIR}/us-east-1_tmp.log \
> ${US_EAST_1_ACTLOG_DIR}/us-east-1_${COLLECT_DATE}.log
rm ${US_EAST_1_ACTLOG_DIR}/us-east-1_tmp.log

$ splunk monitor reload
expect -c "
spawn /opt/splunk/bin/splunk reload monitor
expect \"Splunk username:\"
send -- \"${SPLUNK_USER}\n\"
expect \"Password:\"
send -- \"${SPLUNK_PASS}\n\"
expect \"Monitor inputs reloaded\"
send -- \"exit\n\"
"
sleep 1m

$ ObjectStorage unmounting
umount ${OBST_MOUNTPOINT}
if [ "$?" -eq 0 ]
then
  exit 0
else
  exit 1
fi

  • common.conf
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$ Common definition
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
export SHELL_CNF_DIR=/var/tmp/Actlog_collect/conf  ⇒「conf」ディレクトリのパスを指定
export NIFTY_ACCESS_KEY_ID=XXXXXXXXXXXXXXXXXX  ⇒実行環境のアクセスキーを指定
export GOOFYS_CMDPATH=/root/go/bin/goofys  ⇒「goofys」コマンドのフルパスを指定
export OBST_ENDPOINT=http://xxxxxxxxxxx  ⇒オブジェクトストレージのエンドポイントを指定
export OBST_BUCKETNAME=20181q-kensyo-bucket  ⇒オブジェクトストレージのバケット名を指定
export OBST_MOUNTPOINT=/ObjectStorage  ⇒オブジェクトストレージのマウントポイントを指定
export NIFTY_CLOUD_HOME=/usr/local/src/NIFTY_Cloud_api-tools
export NIFTY_SECRET_KEY=`base64 -d ${SHELL_CNF_DIR}/SecretAccessKey`
export SPLUNK_USER=`base64 -d ${SHELL_CNF_DIR}/Splunk_user`
export SPLUNK_PASS=`base64 -d ${SHELL_CNF_DIR}/Splunk_pass`
export JAVA_HOME=/usr/lib/jvm/jre
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:${JAVA_HOME}/bin:${NIFTY_CLOUD_HOME}/bin
export COLLECT_DATE=`date +"%Y%m%d" --date "1 day ago"`
export AWS_ACCESS_KEY_ID=${NIFTY_ACCESS_KEY_ID}
export AWS_SECRET_ACCESS_KEY=${NIFTY_SECRET_KEY}
export AWS_DEFAULT_OUTPUT=text

$ east-1
EAST_1_ACTLOG_DIR=${OBST_MOUNTPOINT}/Actlog/east-1

$ east-2
EAST_2_ACTLOG_DIR=${OBST_MOUNTPOINT}/Actlog/east-2

$ east-3
EAST_3_ACTLOG_DIR=${OBST_MOUNTPOINT}/Actlog/east-3

$ jp-east-4
JP_EAST_4_ACTLOG_DIR=${OBST_MOUNTPOINT}/Actlog/jp-east-4

$ west-1
WEST_1_ACTLOG_DIR=${OBST_MOUNTPOINT}/Actlog/west-1

$ us-east-1
US_EAST_1_ACTLOG_DIR=${OBST_MOUNTPOINT}/Actlog/us-east-1

パフォーマンスチャート収集スクリプト_ソースコード

  • Perfchart_collect.sh
$!/bin/bash

$ Common function Reading
. /var/tmp/Perfchart_collect/conf/common.conf   ⇒スクリプトの配置先ディレクトリを指定

$ ObjectStorage mounting
if ! mountpoint -q /ObjectStorage ;then
    ${GOOFYS_CMDPATH} --endpoint ${OBST_ENDPOINT} ${OBST_BUCKETNAME} ${OBST_MOUNTPOINT}
fi

$$$ east-1

$ endpoint setting
export NIFTY_CLOUD_URL=https://computing.jp-east-1.api.cloud.nifty.com/api/

$ Server List creation
nifty-describe-instances | grep '^\s*INSTANCE' > ${SHELL_CNF_DIR}/${EAST_1_SERVER_LIST}.tmp
sed -e 's/  /,/g' ${SHELL_CNF_DIR}/${EAST_1_SERVER_LIST}.tmp | cut -d ',' -f 2 \
> ${SHELL_CNF_DIR}/${EAST_1_SERVER_LIST}

while read ServerName ;do
    $ If the server name is comment out or empty, the line is skips
    test -z "${ServerName}" && continue
    echo ${ServerName} | grep '^$.*' > /dev/null && continue

    $ Directory creation
    if ! [ -e ${EAST_1_PERFCHART_DIR}/${ServerName} ];then
    mkdir -p ${EAST_1_PERFCHART_DIR}/${ServerName}
    chmod 755 ${EAST_1_PERFCHART_DIR}/${ServerName}
    chown root:root ${EAST_1_PERFCHART_DIR}/${ServerName}
    fi

    $ CLI execution
    for dtype in cpu memory volume network ping status ;do
        nifty-describe-performance-chart Server --resource-name ${ServerName} \
        --data-type ${dtype} -f ${COLLECT_DATE} -t ${COLLECT_DATE} | grep -v '^\s*CHART' \
        > ${EAST_1_PERFCHART_DIR}/${ServerName}/${ServerName}_${dtype}_${COLLECT_DATE}.log
    done
done < ${SHELL_CNF_DIR}/${EAST_1_SERVER_LIST}

$ Server List deletion
rm ${SHELL_CNF_DIR}/${EAST_1_SERVER_LIST}*

$$$ east-2

$ endpoint setting
export NIFTY_CLOUD_URL=https://computing.jp-east-2.api.cloud.nifty.com/api/

$ Server List creation
nifty-describe-instances | grep '^\s*INSTANCE' > ${SHELL_CNF_DIR}/${EAST_2_SERVER_LIST}.tmp
sed -e 's/  /,/g' ${SHELL_CNF_DIR}/${EAST_2_SERVER_LIST}.tmp | cut -d ',' -f 2 \
> ${SHELL_CNF_DIR}/${EAST_2_SERVER_LIST}

while read ServerName ;do
    $ If the server name is comment out or empty, the line is skips
    test -z "${ServerName}" && continue
    echo ${ServerName} | grep '^$.*' > /dev/null && continue

    $ Directory creation
    if ! [ -e ${EAST_2_PERFCHART_DIR}/${ServerName} ];then
    mkdir -p ${EAST_2_PERFCHART_DIR}/${ServerName}
    chmod 755 ${EAST_2_PERFCHART_DIR}/${ServerName}
    chown root:root ${EAST_2_PERFCHART_DIR}/${ServerName}
    fi

    $ CLI execution
    for dtype in cpu memory volume network ping status ;do
        nifty-describe-performance-chart Server --resource-name ${ServerName} \
        --data-type ${dtype} -f ${COLLECT_DATE} -t ${COLLECT_DATE} | grep -v '^\s*CHART' \
        > ${EAST_2_PERFCHART_DIR}/${ServerName}/${ServerName}_${dtype}_${COLLECT_DATE}.log
    done
done < ${SHELL_CNF_DIR}/${EAST_2_SERVER_LIST}

$ Server List deletion
rm ${SHELL_CNF_DIR}/${EAST_2_SERVER_LIST}*

$$$ east-3

$ endpoint setting
export NIFTY_CLOUD_URL=https://computing.jp-east-3.api.cloud.nifty.com/api/

$ Server List creation
nifty-describe-instances | grep '^\s*INSTANCE' > ${SHELL_CNF_DIR}/${EAST_3_SERVER_LIST}.tmp
sed -e 's/  /,/g' ${SHELL_CNF_DIR}/${EAST_3_SERVER_LIST}.tmp | cut -d ',' -f 2 \
> ${SHELL_CNF_DIR}/${EAST_3_SERVER_LIST}

while read ServerName ;do
    $ If the server name is comment out or empty, the line is skips
    test -z "${ServerName}" && continue
    echo ${ServerName} | grep '^$.*' > /dev/null && continue

    $ Directory creation
    if ! [ -e ${EAST_3_PERFCHART_DIR}/${ServerName} ];then
    mkdir -p ${EAST_3_PERFCHART_DIR}/${ServerName}
    chmod 755 ${EAST_3_PERFCHART_DIR}/${ServerName}
    chown root:root ${EAST_3_PERFCHART_DIR}/${ServerName}
    fi

    $ CLI execution
    for dtype in cpu memory volume network ping status ;do
        nifty-describe-performance-chart Server --resource-name ${ServerName} \
        --data-type ${dtype} -f ${COLLECT_DATE} -t ${COLLECT_DATE} | grep -v '^\s*CHART' \
        > ${EAST_3_PERFCHART_DIR}/${ServerName}/${ServerName}_${dtype}_${COLLECT_DATE}.log
    done
done < ${SHELL_CNF_DIR}/${EAST_3_SERVER_LIST}

$ Server List deletion
rm ${SHELL_CNF_DIR}/${EAST_3_SERVER_LIST}*

$$$ jp-east-4

$ endpoint setting
export NIFTY_CLOUD_URL=https://computing.jp-east-4.api.cloud.nifty.com/api/

$ Server List creation
nifty-describe-instances | grep '^\s*INSTANCE' > ${SHELL_CNF_DIR}/${JP_EAST_4_SERVER_LIST}.tmp
sed -e 's/  /,/g' ${SHELL_CNF_DIR}/${JP_EAST_4_SERVER_LIST}.tmp | cut -d ',' -f 2 \
> ${SHELL_CNF_DIR}/${JP_EAST_4_SERVER_LIST}

while read ServerName ;do
    $ If the server name is comment out or empty, the line is skips
    test -z "${ServerName}" && continue
    echo ${ServerName} | grep '^$.*' > /dev/null && continue

    $ Directory creation
    if ! [ -e ${JP_EAST_4_PERFCHART_DIR}/${ServerName} ];then
    mkdir -p ${JP_EAST_4_PERFCHART_DIR}/${ServerName}
    chmod 755 ${JP_EAST_4_PERFCHART_DIR}/${ServerName}
    chown root:root ${JP_EAST_4_PERFCHART_DIR}/${ServerName}
    fi

    $ CLI execution
    for dtype in cpu memory volume network ping status ;do
        nifty-describe-performance-chart Server --resource-name ${ServerName} \
        --data-type ${dtype} -f ${COLLECT_DATE} -t ${COLLECT_DATE} | grep -v '^\s*CHART' \
        > ${JP_EAST_4_PERFCHART_DIR}/${ServerName}/${ServerName}_${dtype}_${COLLECT_DATE}.log
    done
done < ${SHELL_CNF_DIR}/${JP_EAST_4_SERVER_LIST}

$ Server List deletion
rm ${SHELL_CNF_DIR}/${JP_EAST_4_SERVER_LIST}*

$$$ west-1

$ endpoint setting
export NIFTY_CLOUD_URL=https://computing.jp-west-1.api.cloud.nifty.com/api/

$ Server List creation
nifty-describe-instances | grep '^\s*INSTANCE' > ${SHELL_CNF_DIR}/${WEST_1_SERVER_LIST}.tmp
sed -e 's/  /,/g' ${SHELL_CNF_DIR}/${WEST_1_SERVER_LIST}.tmp | cut -d ',' -f 2 \
> ${SHELL_CNF_DIR}/${WEST_1_SERVER_LIST}

while read ServerName ;do
    $ If the server name is comment out or empty, the line is skips
    test -z "${ServerName}" && continue
    echo ${ServerName} | grep '^$.*' > /dev/null && continue

    $ Directory creation
    if ! [ -e ${WEST_1_PERFCHART_DIR}/${ServerName} ];then
    mkdir -p ${WEST_1_PERFCHART_DIR}/${ServerName}
    chmod 755 ${WEST_1_PERFCHART_DIR}/${ServerName}
    chown root:root ${WEST_1_PERFCHART_DIR}/${ServerName}
    fi

    $ CLI execution
    for dtype in cpu memory volume network ping status ;do
        nifty-describe-performance-chart Server --resource-name ${ServerName} \
        --data-type ${dtype} -f ${COLLECT_DATE} -t ${COLLECT_DATE} | grep -v '^\s*CHART' \
        > ${WEST_1_PERFCHART_DIR}/${ServerName}/${ServerName}_${dtype}_${COLLECT_DATE}.log
    done
done < ${SHELL_CNF_DIR}/${WEST_1_SERVER_LIST}

$ Server List deletion
rm ${SHELL_CNF_DIR}/${WEST_1_SERVER_LIST}*

$$$ us-east-1

$ endpoint setting
export NIFTY_CLOUD_URL=https://computing.us-east-1.api.cloud.nifty.com/api/

$ Server List creation
nifty-describe-instances | grep '^\s*INSTANCE' > ${SHELL_CNF_DIR}/${US_EAST_1_SERVER_LIST}.tmp
sed -e 's/  /,/g' ${SHELL_CNF_DIR}/${US_EAST_1_SERVER_LIST}.tmp | cut -d ',' -f 2 \
> ${SHELL_CNF_DIR}/${US_EAST_1_SERVER_LIST}

while read ServerName ;do
    $ If the server name is comment out or empty, the line is skips
    test -z "${ServerName}" && continue
    echo ${ServerName} | grep '^$.*' > /dev/null && continue

    $ Directory creation
    if ! [ -e ${US_EAST_1_PERFCHART_DIR}/${ServerName} ];then
    mkdir -p ${US_EAST_1_PERFCHART_DIR}/${ServerName}
    chmod 755 ${US_EAST_1_PERFCHART_DIR}/${ServerName}
    chown root:root ${US_EAST_1_PERFCHART_DIR}/${ServerName}
    fi

    $ CLI execution
    for dtype in cpu memory volume network ping status ;do
        nifty-describe-performance-chart Server --resource-name ${ServerName} \
        --data-type ${dtype} -f ${COLLECT_DATE} -t ${COLLECT_DATE} | grep -v '^\s*CHART' \
        > ${US_EAST_1_PERFCHART_DIR}/${ServerName}/${ServerName}_${dtype}_${COLLECT_DATE}.log
    done
done < ${SHELL_CNF_DIR}/${US_EAST_1_SERVER_LIST}

$ Server List deletion
rm ${SHELL_CNF_DIR}/${US_EAST_1_SERVER_LIST}*

$ splunk monitor reload
expect -c "
spawn /opt/splunk/bin/splunk reload monitor
expect \"Splunk username:\"
send -- \"${SPLUNK_USER}\n\"
expect \"Password:\"
send -- \"${SPLUNK_PASS}\n\"
expect \"Monitor inputs reloaded\"
send -- \"exit\n\"
"
sleep 1m

$ ObjectStorage unmounting
umount ${OBST_MOUNTPOINT}
if [ "$?" -eq 0 ]
then
  exit 0
else
  exit 1
fi

  • common.conf
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$ Common definition
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
export SHELL_CNF_DIR=/var/tmp/Perfchart_collect/conf   ⇒「conf」ディレクトリのパスを指定
export NIFTY_ACCESS_KEY_ID=XXXXXXXXXXXXXXXXXX  ⇒実行環境のアクセスキーを指定
export GOOFYS_CMDPATH=/root/go/bin/goofys  ⇒「goofys」コマンドのフルパスを指定
export OBST_ENDPOINT=http://xxxxxxxxxxx  ⇒オブジェクトストレージのエンドポイントを指定
export OBST_BUCKETNAME=20181q-kensyo-bucket  ⇒オブジェクトストレージのバケット名を指定
export OBST_MOUNTPOINT=/ObjectStorage  ⇒オブジェクトストレージのマウントポイントを指定export NIFTY_CLOUD_HOME=/usr/local/src/NIFTY_Cloud_api-tools
export NIFTY_SECRET_KEY=`base64 -d ${SHELL_CNF_DIR}/SecretAccessKey`
export SPLUNK_USER=`base64 -d ${SHELL_CNF_DIR}/Splunk_user`
export SPLUNK_PASS=`base64 -d ${SHELL_CNF_DIR}/Splunk_pass`
export JAVA_HOME=/usr/lib/jvm/jre
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:${JAVA_HOME}/bin:${NIFTY_CLOUD_HOME}/bin
export COLLECT_DATE=`date +"%Y%m%d" --date "1 day ago"`
export AWS_ACCESS_KEY_ID=${NIFTY_ACCESS_KEY_ID}
export AWS_SECRET_ACCESS_KEY=${NIFTY_SECRET_KEY}
export AWS_DEFAULT_OUTPUT=text

$ east-1
EAST_1_PERFCHART_DIR=${OBST_MOUNTPOINT}/PerfChart/east-1
EAST_1_SERVER_LIST=east-1_server

$ east-2
EAST_2_PERFCHART_DIR=${OBST_MOUNTPOINT}/PerfChart/east-2
EAST_2_SERVER_LIST=east-2_server

$ east-3
EAST_3_PERFCHART_DIR=${OBST_MOUNTPOINT}/PerfChart/east-3
EAST_3_SERVER_LIST=east-3_server

$ jp-east-4
JP_EAST_4_PERFCHART_DIR=${OBST_MOUNTPOINT}/PerfChart/jp-east-4
JP_EAST_4_SERVER_LIST=jp-east-4_server

$ west-1
WEST_1_PERFCHART_DIR=${OBST_MOUNTPOINT}/PerfChart/west-1
WEST_1_SERVER_LIST=west-1_server

$ us-east-1
US_EAST_1_PERFCHART_DIR=${OBST_MOUNTPOINT}/PerfChart/us-east-1
US_EAST_1_SERVER_LIST=us-east-1_server

まとめ

今回はニフクラで収集できる各種ログを自動で収集し、解析するところまでを実装してみました。
簡易的ではありますが、ニフクラ上でログの収集、解析という話が出た際のご参考にしていただけると幸いです。
解析まで行わなくても、ログを収集しておいてオブジェクトストレージに格納しておく作業だけでも参考になると思います。

※注意事項

  • 本記事については検証結果の1つとなります。実際に検討される場合は、事前にそれぞれの要件を鑑みて実装するか確認してください。
  • 本記事ではOS上の操作についても記載していますが、ニフクラではOS以上はご利用者様の責任範囲となりますのでご留意ください。