LoginSignup
4
1

Google Spread Sheetの情報をSplunkのlookupに定期的に取り込む

Last updated at Posted at 2019-04-04

いつもの前置き

・Splunkには色々なAppがある。
・とはいえコミュニティサポート(英語)のAppは始めるまでにちょっと敷居が高い。
・そこで私がトライした内容は後学のために共有したいと思いここに書き残します。
・ゆるい情報なので参考程度でご勘弁。

更新

  • 2021.01.19 最新のAdd-Onに更新したあとに連携失敗していたので[Google Sheets API]を有効化
  • 2022.12.17 Add-onのSet Upメニューが見当たらないためワークアラウンドを記載
  • 2023.06.24 12.17作成のワークアラウンドも設定しづらいため修正

「Google Spread Sheetを使ってアセット台帳を管理しているが、この台帳情報をSplunk側に自動連携させてサーチ時に参照させたい」

・利用App
Google Import/Export
https://splunkbase.splunk.com/app/2630/

セットアップ手順

参考元の手順はこちら
https://lukemurphey.net/projects/splunk-google-docs/wiki/How_to_setup_app
※github上の詳細版
https://github.com/LukeMurphey/splunk-google-drive/tree/master/src

GDrive連携のAPIセットアップ

スクリーンショット 2019-10-03 21.10.24.png
  • IAMと管理 - サービスアカウントをクリック
スクリーンショット 2019-10-03 21.12.24.png
  • +サービスアカウントを作成し、JSON形式の鍵をダウンロード
    image.pngimage.png

  • Google Driveにてexcelを作成

    • 共有対象にサービスアカウントのメールアドレスを指定image.png

Splunkセットアップ

  • Appをインストール
スクリーンショット 2019-10-04 10.56.10.png

※2022.12.17: Splunk Ver9.0.2とGoogled Drive App 2.0.6の組み合わせでSetupメニューが表示されなかったため、appのview権限を表示して、Appの起動を実施
※ 2023.06.24 上記ワークアラウンドも設定しづらいため修正

  • 「Setup」メニューが見当たらないため下記ワークアラウンド(URLで直接セットアップページにアクセス)を実施

Open the setup view in the app to upload the service account key. The setup view can be accessed at google_drive_setup (e.g. http://MySplunkInstall:8000/en-US/app/search/google_drive_setup).

  • GCPで作成したサービスアカウントの鍵を登録!
スクリーンショット 2019-10-04 11.01.45.png
  • 正常に鍵が登録された場合の画面
    スクリーンショット 2023-06-24 15.13.46.png

  • 事前にLookupファイルを作成し、定義しておく

スクリーンショット 2019-10-04 11.06.03.png
  • 「設定」→「ルックアップ」にて、①テーブルファイルのUploadをして、②ルックアップ定義を実施しておく。

スクリーンショット 2023-06-24 15.29.13.png

  • 設定-入力-Google Spreadsheetにて取込定義を作成image.png

正常動作確認のため1分間隔で取り込みを行い、エラーがなければ後で適切な頻度に戻すことを推奨

  • 1m(1分)間隔でlookupに自動アップデートされることを確認image.png

  • Appの動作に関する内部ログを見るダッシュボードがAPI連携の成功可否を確認する上で便利

734FB3FA-D576-4E18-8B4A-80EE4243AD52.png

以下はトラブルシューティングメモ

  • (2021.01.19追加)
    • lookupが更新されていないことに気づき、index=_internalにて以下エラーを確認
021-01-19 13:29:54,223 ERROR A general exception was thrown when executing the import
Traceback (most recent call last):
  File "/opt/splunk/etc/apps/google_drive/bin/google_spreadsheet.py", line 223, in import_file
    last_updated = google_lookup_sync.import_to_lookup_file(lookup_name, None, None, spreadsheet_title, worksheet_name, session_key, create_if_non_existent=False)
  File "/opt/splunk/etc/apps/google_drive/bin/google_drive_app/__init__.py", line 379, in import_to_lookup_file
    return self.import_to_lookup_file_full_path(destination_full_path, namespace, owner, google_spread_sheet_name, worksheet_name, session_key, create_if_non_existent, lookup_name=lookup_name)
  File "/opt/splunk/etc/apps/google_drive/bin/google_drive_app/__init__.py", line 431, in import_to_lookup_file_full_path
    google_work_sheet = self.get_or_make_sheet_if_necessary(google_spread_sheet, worksheet_name)
  File "/opt/splunk/etc/apps/google_drive/bin/google_drive_app/__init__.py", line 515, in get_or_make_sheet_if_necessary
    worksheet = google_spread_sheet.worksheet(worksheet_name)
  File "/opt/splunk/etc/apps/google_drive/bin/google_drive_app/gspread/models.py", line 235, in worksheet
    sheet_data = self.fetch_sheet_metadata()
  File "/opt/splunk/etc/apps/google_drive/bin/google_drive_app/gspread/models.py", line 184, in fetch_sheet_metadata
    r = self.client.request('get', url, params=params)
  File "/opt/splunk/etc/apps/google_drive/bin/google_drive_app/gspread/client.py", line 79, in request
    raise APIError(response)
APIError: {
  "error": {
    "code": 403,
    "message": "Google Sheets API has not been used in project xxxxxxx before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/sheets.googleapis.com/overview?project=xxxxxxx then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1