2017-01-10 23 views
0

我試圖找到或創建一個Sensu插件來統計文件夾中的AWS S3對象。例如,試圖找到一個Sensu插件AWS S3

所有桶/ TEST1/TEST2/

我想知道有多少個對象test2的範圍內,如果數變爲高於閾值提醒我。

我發現了這個,但是我無法讓它工作。

# by default you only get 1000 objects at a time 
# so you have to roll your own cursor 

S3.connect! 

objects = [] 
last_key = nil 
begin 
    new_objects = AWS::S3::Bucket.objects(bucket_name, :marker => last_key) 
    objects += new_objects 
    last_key = objects.last.key 
end while new_objects.size > 0 

# you can easily define the above as an all_objects method on AWS::S3::Bucket 

如果有人知道以不同的方式做到這一點,請讓我知道。

謝謝

德文

+0

你看到什麼錯誤?你配置了你的憑證嗎? – thun

+0

@thun我配置了我的憑證,我有其他AWS rb腳本可以工作。我試圖運行這個腳本,它似乎錯誤了。當然,我不知道這個腳本的語法,我是Ruby的新手。其他腳本有很好的評論示例。我運行腳本./all_s3_objects.rb並得到:./all_s3_objects.rb:第4行:S3.connect !:命令未找到 ./all_s3_objects.rb:第6行:objects:command not found – Devon

回答

1

,我決定走了不同的路線,我用這個代碼來完成我想做的事。

#!/bin/bash 
value=$(aws s3 ls bucket/dir1/dir2/ -- recursive --human-readable --summarize | grep .file type | wc -l) 
if [ $value -gt 1000 ]; 
then 
     echo "$value Warning" 
     exit 2 
fi 

謝謝大家的幫助

德文