4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

IBM Cloud Activity Tracker with LogDNAから直近のアクティビティをCSV形式で出力してみた

Last updated at Posted at 2020-09-08

はじめに

IBM Cloud Activity Tracker with LogDNAはIBM Cloud上のアクティビティーを(監査目的などで)モニタリングすることが可能なサービスである。主にUIからダッシュボードなどでアクティビティーを確認できるし、IBM Cloud Object Storage(ICOS)などにそのログをアーカイブして保存しておくことができる。
本稿では、IBM Cloud Activity Tracker with LogDNAへコマンド一発で直近のアクティビティをCSV形式で出力する方法を紹介する。

1. Activity Tracker with LogDNAを注文する

(省略)

2. Export機能が有効化されていることを確認。

image.png

3. Service Keyを作成する。

image.png

4. APIを使ってアクセス。

ポイント

  1. IBM Cloud docsにはpublic endpointしか記載されていないが、private endpointでもアクセスできる。
    https://cloud.ibm.com/docs/Activity-Tracker-with-LogDNA?topic=Activity-Tracker-with-LogDNA-endpoints
    例えば、https://api.jp-tok.logging.cloud.ibm.comの代わりに、https://api.private.jp-tok.logging.cloud.ibm.comのようにprivateを含めてアクセスすればよい。もしIBM Cloud上のVSIなどからコマンドを叩けば、Internetに出ることなくログを出力することができる。
  2. IBM Cloud docsには-u USERIDでユーザーIDを指定しているが、パスワード(Service Key)も一緒に指定したければ-u USERID:SERVICEKEYと指定すれば良い。
  3. データの昇順、降順の好みがあるが、私は最新のログは一番下に出てきてほしいので、prefer=headを指定。
  4. 抽出するログの指定のために、toは$(date +%s)000で現在時刻を指定、fromは$(($(date +%s)-3600))000で1時間前を指定。
  5. CSV形式で出力したいので|@csvを指定。
$ USERID=xxxxx
$ SERVICEKEY=yyyyy
$ curl -s "https://api.private.jp-tok.logging.cloud.ibm.com/v1/export?to=$(date +%s)000&from=$(($(date +%s)-3600))000&prefer=head" -u "$USERID:$SERVICEKEY"|jq -r '[.eventTime, ._platform, .message, .action, .outcome, .initiator.name]|@csv'

(略)
"2020-09-08T08:06:04.98+0000","is","Subnet for VPC: read subnet khayama-iks-subnet-01","is.subnet.subnet.read","success","xxx@xxxxxx"
"2020-09-08T08:06:06.72+0000","is","Subnet for VPC: read subnet vpc-kishida-subnet-tok2","is.subnet.subnet.read","success","xxx@xxxxxx"
"2020-09-08T08:06:07.29+0000","is","Subnet for VPC: read subnet asasaki-subnet1","is.subnet.subnet.read","success","xxx@xxxxxx"
"2020-09-08T08:06:54Z","cloudshell",,"cloudshell.server.create","success","yyy@yyyyyy"
"2020-09-08T08:07:59Z","cloudshell",,"cloudshell.server.delete","success","yyy@yyyyyy"
"2020-09-08T08:08:00Z","cloudshell",,"cloudshell.server.create","success","yyy@yyyyyy"
"2020-09-08T08:08:27Z","cloudshell",,"cloudshell.server.configure","success","yyy@yyyyyy"
"2020-09-08T08:09:13.93+0000","is","Subnet for VPC: read subnet sub-10-0-0-0-24","is.subnet.subnet.read","success","xxx@xxxxxx"
"2020-09-08T08:09:14.54+0000","is","Subnet for VPC: read subnet sub-10-1-0-0-24","is.subnet.subnet.read","success","xxx@xxxxxx"
(略)

上記結果から、xxxさんはVPCを触っているのねー、yyyさんはCloudShellを触っているねー、などがわかる。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?