NTNX>日記

個人的な趣味による Nutanix Community Edition 日記。Japanese のみですみません。

Nutanix CE のタイムスタンプをJSTに変換する。(PowerShell)

Nutanix CE から Nutanix Cmdlets で取得する情報のタイムスタンプは、だいたいTimeStampInUsecs となっていて、マイクロ秒の UNIX time です。わかりにくいので、おおまかにJSTに変換してみます。

ためしにアラートを 5件だけ取得すると、タイムスタンプは下記のようになります。

NTNX> Get-NTNXAlert | select createdTimeStampInUsecs,lastOccurrenceTimeStampInUsecs,message | select -First 5

createdTimeStampInUsecs lastOccurrenceTimeStampInUsecs message
----------------------- ------------------------------ -------
       1507512610308168               1507512610308168 Protection domain pd-jbox01 replication to remote site ntnx-gb failed. Protection Domain is...
       1507509266716569               1507509266716569 The replication for snapshot with id (1503639670637607163, 1502412186468169, 13938) of prot...
       1507509005187522               1507511706068109 Failed to send email from Controller VM 192.168.1.193 via SMTP server 192.168.1.193:2525 du...
       1507508959556258               1507508959556258 The replication for snapshot with id (1503639670637607163, 1502412186468169, 13805) of prot...
       1507485997901288               1507485997901288 The replication for snapshot with id (1503639670637607163, 1502412186468169, 13310) of prot...

下記のようなファンクションを作成しておきます。

こんな感じに、日本時間にできます。

NTNX> function timestamp_us2jst($timestamp_us){
>> $ts_base = Get-Date "1970/1/1"
>> $ts_base = $ts_base.AddHours(9)
>> $ts_base.AddSeconds($timestamp_us / 1000000)
>> }
NTNX> Get-NTNXAlert | select `
>> @{N="createdTimeJST";E={timestamp_us2jst $_.createdTimeStampInUsecs}},
>> @{N="lastOccurrenceJST";E={timestamp_us2jst $_.lastOccurrenceTimeStampInUsecs}},
>> message |
>> select -First 5

createdTimeJST      lastOccurrenceJST   message
--------------      -----------------   -------
2017/10/09 10:30:10 2017/10/09 10:30:10 Protection domain pd-jbox01 replication to remote site ntnx-gb failed. Protection Domain is active on remote.
2017/10/09 9:34:26  2017/10/09 9:34:26  The replication for snapshot with id (1503639670637607163, 1502412186468169, 13938) of protection domain p...
2017/10/09 9:30:05  2017/10/09 10:15:06 Failed to send email from Controller VM 192.168.1.193 via SMTP server 192.168.1.193:2525 due to following ...
2017/10/09 9:29:19  2017/10/09 9:29:19  The replication for snapshot with id (1503639670637607163, 1502412186468169, 13805) of protection domain p...
2017/10/09 3:06:37  2017/10/09 3:06:37  The replication for snapshot with id (1503639670637607163, 1502412186468169, 13310) of protection domain p...

以上。

©2023 gowatana
クリエイティブ・コモンズ・ライセンスこの 作品 は クリエイティブ・コモンズ 表示 4.0 国際 ライセンスの下に提供されています。