LoginSignup
0
0

More than 1 year has passed since last update.

Umbrella S3 ログを aws cli から直接参照する

Last updated at Posted at 2022-09-12

はじめに

以前 Umbrella の S3 ログをデスクトップクライアント(Cyberduck)を使ってアクセスする方法を紹介した。
https://qiita.com/urikura/items/1fccd893f2f483f1f7ec
いちいちローカルにファイルを保存して操作するのが面倒な場合に備えて CLI 操作する方法も調べてみた。

準備

awscli インストール

=> https://docs.aws.amazon.com/ja_jp/cli/latest/userguide/getting-started-install.html

aws configure

=> https://docs.aws.amazon.com/ja_jp/cli/latest/userguide/cli-configure-quickstart.html

Umbrella で生成したクレデンシャルを設定

$ aws configure
AWS Access Key ID [****************FQBK]: 
AWS Secret Access Key [****************aZOu]: 
Default region name [us-west-2]: 
Default output format [None]: 

確認

$ aws configure list
      Name                    Value             Type    Location
      ----                    -----             ----    --------
   profile                <not set>             None    None
access_key     ****************FQBK shared-credentials-file    
secret_key     ****************aZOu shared-credentials-file    
    region                us-west-2      config-file    ~/.aws/config

S3 アクセスの確認

*バケツ名や IP などはマスクしてます。

ルートと各機能ごとの階層

$ aws s3 ls s3://umbrella-managed-yyy-xxx/
                           PRE auditlogs/
                           PRE dnslogs/
                           PRE proxylogs/

各機能ごとの日付ディレクトリ

$ aws s3 ls s3://umbrella-managed-yyy-xxx/dnslogs/
                           PRE 2022-08-11/
                           PRE 2022-08-12/
                           PRE 2022-08-13/
                           PRE 2022-08-14/
                           PRE 2022-08-15/
                           PRE 2022-08-16/
                           PRE 2022-08-17/
                           PRE 2022-08-18/
                           PRE 2022-08-19/
                           PRE 2022-08-20/

ファイル一覧

$ aws s3 ls s3://umbrella-managed-yyy-xxx/dnslogs --recursive
2022-08-12 00:04:36        380 dnslogs/2022-08-11/2022-08-11-23-50-44ea.csv.gz
2022-08-12 00:01:57        367 dnslogs/2022-08-11/2022-08-11-23-50-91dd.csv.gz
2022-08-12 00:04:00        471 dnslogs/2022-08-11/2022-08-11-23-50-a6fd.csv.gz

ファイルの中身を見る

aws s3 cp s3://{bucket}/{path}/{filename} - | zcat を使う。
さらにパイプで grep なども可能。
宛先に- を指定することで標準出力することが可能。zcat に渡すことで可読となる。

$ aws s3 cp s3://umbrella-managed-yyy-xxx/dnslogs/2022-09-12/2022-09-12-05-30-cb6f.csv.gz - | zcat
"2022-09-12 05:34:08","Site-PPPoE","Site-PPPoE","xx.xx.xx.xx","xx.xx.xx.xx","Allowed","1 (A)","NOERROR","gae2-spclient.spotify.com.","Radio,Music,Podcasts,Application,Streaming Audio"
"2022-09-12 05:37:03","Site-IPv6","Site-IPv6","xx:xx:xx:xx:xx:xx:xx:xx","xx:xx:xx:xx:xx:xx:xx:xx","Allowed","1 (A)","NOERROR","app.slack.com.","Chat,Instant Messaging,Application,Chat and Instant Messaging"

展望

複数ファイルを横断した検索はローカル作業が必要。これも CLI だけで完結できるとより実用性がありそう。

参考

https://qiita.com/mimimi-no-sesese/items/0e7955172ab53ccbbde1
https://qiita.com/nakazax/items/b62309884a19d71f9a34
https://docs.aws.amazon.com/cli/latest/reference/s3/cp.html

0
0
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
0
0