阅读背景:

试图找到一个Sensu插件AWS S3

来源:互联网 

I'm trying to find or create a Sensu plugin to count AWS S3 objects within a folder. For example,

我正在尝试查找或创建一个Sensu插件来计算文件夹中的AWS S3对象。例如,

All buckets/test1/test2/

所有水桶/ test1 / test2 /

I want to know how many objects are within test2 and alert me if the number goes above the threshold.

我想知道test2中有多少个对象,如果数字超过阈值则提醒我。

I found this, but I'n not able to get it to work.

我发现了这个,但我无法让它发挥作用。

# 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

If anyone knows a different way to do this, please let me know.

如果有人知道不同的方法,请告诉我。

Thank you

谢谢

Devon

德文

1 个解决方案

#1


1  

I decided to go a different route, I used this code to accomplish what I wanted to do.

我决定走另一条路,我用这段代码完成了我想做的事。

#!/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

Thank you Everyone for the help

谢谢大家的帮助

Devon

德文


分享到: