{"id":4283,"date":"2019-12-03T15:40:33","date_gmt":"2019-12-03T06:40:33","guid":{"rendered":"https:\/\/www.ecomottblog.com\/?p=4283"},"modified":"2019-12-11T16:28:15","modified_gmt":"2019-12-11T07:28:15","slug":"%e8%a4%87%e6%95%b0%e3%82%a2%e3%82%ab%e3%82%a6%e3%83%b3%e3%83%88%e3%81%aeec2%e3%83%aa%e3%82%bd%e3%83%bc%e3%82%b9%e4%b8%80%e8%a6%a7%e3%82%92backlog%e3%81%aewiki%e3%81%ab%e8%87%aa%e5%8b%95%e6%8a%95","status":"publish","type":"post","link":"https:\/\/test.ecomottblog.com\/?p=4283","title":{"rendered":"\u8907\u6570\u30a2\u30ab\u30a6\u30f3\u30c8\u306eEC2\u30ea\u30bd\u30fc\u30b9\u4e00\u89a7\u3092Backlog\u306ewiki\u306b\u81ea\u52d5\u6295\u7a3f"},"content":{"rendered":"<p>\u30a2\u30c9\u30d9\u30f3\u30c8\u30ab\u30ec\u30f3\u30c0\u30fc3\u65e5\u76ee\u3067\u3059\u3002<\/p>\n<p>\u5f0a\u793e\u3067\u306f\u69d8\u3005\u306a\u4e8b\u60c5\u306b\u3088\u308a\u8907\u6570\u306eAWS\u30a2\u30ab\u30a6\u30f3\u30c8\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n\u4eca\u307e\u3067\u306f\u4eba\u529b\u3067AWS\u60c5\u5831\u3092\u4e00\u3064\u306b\u7e8f\u3081\u3066\u3044\u307e\u3057\u305f\u304c\u3001\u305d\u308d\u305d\u308d\u53f0\u6570\u7684\u306b\u9650\u754c\u306b\u81f3\u308a<br \/>\n\u81ea\u52d5\u66f4\u65b0\u3059\u308b\u4ed5\u7d44\u307f\u3092\u30b5\u30af\u30c3\u3068\u4ee5\u4e0b\u306e\u8981\u4ef6\u3067\u4f5c\u6210\u3059\u308b\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002<br \/>\n<!--more--><\/p>\n<ul>\n<li>\u5b9a\u671f\u7684\u306b\u81ea\u52d5\u66f4\u65b0\u3057\u305f\u3044<\/li>\n<li>\u66f4\u65b0\u6642\u306e\u901a\u77e5\u306fSlack\u7b49\u3067\u3088\u3044<\/li>\n<li>CSV\u5f62\u5f0f\u307f\u305f\u3044\u306a\u611f\u3058<\/li>\n<li>\u4fdd\u5b58\u5834\u6240\u306fBacklog\u3067<\/li>\n<\/ul>\n<h3>\u69cb\u6210\u56f3<\/h3>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-4284\" src=\"https:\/\/www.ecomottblog.com\/cmswp\/wp-content\/uploads\/2019\/11\/aws-to-csv-backlog-upload-300x160.png\" alt=\"\" width=\"518\" height=\"276\" srcset=\"https:\/\/test.ecomottblog.com\/wp-content\/uploads\/2019\/11\/aws-to-csv-backlog-upload-300x160.png 300w, https:\/\/test.ecomottblog.com\/wp-content\/uploads\/2019\/11\/aws-to-csv-backlog-upload-304x162.png 304w, https:\/\/test.ecomottblog.com\/wp-content\/uploads\/2019\/11\/aws-to-csv-backlog-upload-282x150.png 282w, https:\/\/test.ecomottblog.com\/wp-content\/uploads\/2019\/11\/aws-to-csv-backlog-upload.png 615w\" sizes=\"(max-width: 518px) 100vw, 518px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>\u8ffd\u52a0\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3084\u74b0\u5883\u306b\u3042\u307e\u308a\u4f9d\u5b58\u3057\u306a\u3044\u3088\u3046\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067\u4f5c\u6210\u3002<\/p>\n<ul>\n<li>aws-cli<\/li>\n<li>jq<\/li>\n<li>curl<\/li>\n<\/ul>\n<p>\u52d5\u4f5c\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002<br \/>\n1. EC2(Amazonlinux2)\u306eCron\u3067\u8d77\u52d5<br \/>\n2. aws-cli \u306b\u3066\u60c5\u5831\u53d6\u5f97\u3057csv\u4f5c\u6210<br \/>\n3. curl\u3067csv\u3092Backlog\u306bupload<br \/>\n4. \u53d6\u5f97\u3057\u305fattachid\u3092curl\u3067wiki\u3068\u7d10\u3065\u3051\u308b<br \/>\n5. slack\u306b\u901a\u77e5<\/p>\n<h4>ec2\u7528script<\/h4>\n<pre><code>#!\/bin\/bash\n\nset -e\n\n# .aws\/credentials\ndeclare -a AWS_ACCOUNT=($(cat &lt;&lt; EOF\naccount_a\naccount_b\naccount_c\nEOF\n))\n\nCSV_PATH=\/home\/example-dir\nCSV_FILE=\"$(date +%Y%m%d)_all_ec2_list.csv\"\n\n# main start \necho \"account,status,Name,Instance-Id,InstanceType,Publicip,Privateip,Zone,Tags01,Tags02,Tags03,Tags04,Tags05,Tags06,Tags07\" &gt;\"${CSV_PATH}\/${CSV_FILE}\"\nfor ac in ${AWS_ACCOUNT[@]};do\n    # set profile\n    aws configure set region ap-northeast-1  --profile \"${ac}\"\n    # awscli main - generate CSV\n    aws ec2 describe-instances --profile \"${ac}\"| jq -r --arg a ${ac}  '.Reservations[].Instances[] | $a + \",\" + .State.Name + \",\" + [.Tags[] | select(.Key == \"Name\").Value][] + \",\" + .InstanceId + \",\" +  .InstanceType + \",\" + .PublicIpAddress + \",\" + .PrivateIpAddress  + \",\" + .Placement.AvailabilityZone + \",\" + ([.Tags[]|.Key + \":\" + .Value + \",\"]|sort|add)' &gt;&gt;\"${CSV_PATH}\/${CSV_FILE}\"\ndone\n\n# Backlog upload main\nAPIKEY=\"xxxxxxxxxxxxxxxxxx-example-api-key-xxxxxxxxxxxxxxxxxxxxxxxxx\"\nUPLOADFILE=\"${CSV_PATH}\/${CSV_FILE}\"\nDOMAIN=example.backlog.com\nWIKIID=999999\n\n# file upload\nRES=\"$(curl -s -F filename=${UPLOADFILE} -F file=@${UPLOADFILE} https:\/\/${DOMAIN}\/api\/v2\/space\/attachment?apiKey=${APIKEY} 2&gt;&amp;1)\"\n\n# get ID (return ATTACHID=\"123456\")\nATTACHID=\"$(echo ${RES}|cut -f 1 -d \",\"|grep -o -E \"[^:]*[0-9]{6}\")\"\n\n# file attach to wiki\ncurl -s -d \"attachmentId[]=${ATTACHID}\" https:\/\/${DOMAIN}\/api\/v2\/wikis\/${WIKIID}\/attachments?apiKey=${APIKEY}\n\n# send slack \ncurl -s -XPOST https:\/\/hooks.slack.com\/services\/xxxxxxx\/xxxxxxx\/xxxxxxxxxxxxxxxxxxxxxxxxx -d '\n  {\n    \"username\":\"CRON from '\"$(hostname)\"'\",\n    \"channel\": \"#example\",\n    \"icon_url\":\"https:\/\/example.com\/icon.png\",\n    \"attachments\": [\n      {\n        \"text\":\"'\"${CSV_FILE}\"'\u306e\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3092\u5b8c\u4e86\u3057\u307e\u3057\u305f\u3002\",\n        \"fallback\":\"'\"${CSV_FILE}\"'\u306e\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3092\u5b8c\u4e86\u3057\u307e\u3057\u305f\u3002\",\n        \"color\":\"good\"\n      },\n    ]\n }'\n\n# All Done.\necho -e \"\\n$(date +'%Y\/%m\/%d %H:%M:%S') :All Done.\"\n<\/code><\/pre>\n<p>\u6210\u529f\u3057\u305f\u3089 slack\u306e\u901a\u77e5\u304c\u3053\u306e\u3088\u3046\u306b\u6765\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-4290\" src=\"https:\/\/www.ecomottblog.com\/cmswp\/wp-content\/uploads\/2019\/11\/slack-300x42.jpg\" alt=\"\" width=\"379\" height=\"53\" srcset=\"https:\/\/test.ecomottblog.com\/wp-content\/uploads\/2019\/11\/slack-300x42.jpg 300w, https:\/\/test.ecomottblog.com\/wp-content\/uploads\/2019\/11\/slack-304x42.jpg 304w, https:\/\/test.ecomottblog.com\/wp-content\/uploads\/2019\/11\/slack-282x39.jpg 282w, https:\/\/test.ecomottblog.com\/wp-content\/uploads\/2019\/11\/slack.jpg 468w\" sizes=\"(max-width: 379px) 100vw, 379px\" \/><\/p>\n<p>\u5b9f\u969b\u306ecsv\u306e\u4e2d\u8eab\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-4390\" src=\"https:\/\/www.ecomottblog.com\/cmswp\/wp-content\/uploads\/2019\/11\/csv-image-300x57.jpg\" alt=\"\" width=\"668\" height=\"127\" srcset=\"https:\/\/test.ecomottblog.com\/wp-content\/uploads\/2019\/11\/csv-image-300x57.jpg 300w, https:\/\/test.ecomottblog.com\/wp-content\/uploads\/2019\/11\/csv-image-768x146.jpg 768w, https:\/\/test.ecomottblog.com\/wp-content\/uploads\/2019\/11\/csv-image-1024x195.jpg 1024w, https:\/\/test.ecomottblog.com\/wp-content\/uploads\/2019\/11\/csv-image-304x58.jpg 304w, https:\/\/test.ecomottblog.com\/wp-content\/uploads\/2019\/11\/csv-image-282x54.jpg 282w, https:\/\/test.ecomottblog.com\/wp-content\/uploads\/2019\/11\/csv-image.jpg 1324w\" sizes=\"(max-width: 668px) 100vw, 668px\" \/><\/p>\n<p>\u5f0a\u793e\u3067\u306f\u3053\u306e\u4ed6\u306e\u30ea\u30bd\u30fc\u30b9\u4e00\u89a7\u3082\u540c\u69d8\u306eScript\u3067\u81ea\u52d5\u66f4\u65b0\u3057\u3066\u3044\u308b\u4ed6\u3001Azure\u306e\u30ea\u30bd\u30fc\u30b9\u306b\u3064\u3044\u3066\u3082Backlog\u306egit\u3092\u5229\u7528\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<h3>\u304a\u308f\u308a\u306b<\/h3>\n<p>\u3044\u304b\u304c\u3060\u3063\u305f\u3067\u3057\u3087\u3046\u304b\u3002<br \/>\n\u8907\u6570\u30a2\u30ab\u30a6\u30f3\u30c8\u306e\u60c5\u5831\u3092\u7e8f\u3081\u308b\u306e\u306f\u5927\u5909\u3067\u3059\u3088\u306d\u3002<\/p>\n<p>\u3053\u306e\u8a18\u4e8b\u304c\u7686\u3055\u307e\u306e\u5feb\u9069\u306a\u30a4\u30f3\u30d5\u30e9\u696d\u52d9\u306e\u4e00\u52a9\u306b\u306a\u308c\u3070\u5e78\u3044\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30a2\u30c9\u30d9\u30f3\u30c8\u30ab\u30ec\u30f3\u30c0\u30fc3\u65e5\u76ee\u3067\u3059\u3002 \u5f0a\u793e\u3067\u306f\u69d8\u3005\u306a\u4e8b\u60c5\u306b\u3088\u308a\u8907\u6570\u306eAWS\u30a2\u30ab\u30a6\u30f3\u30c8\u304c\u3042\u308a\u307e\u3059\u3002 \u4eca\u307e\u3067\u306f\u4eba\u529b\u3067AWS\u60c5\u5831\u3092\u4e00\u3064\u306b\u7e8f\u3081\u3066\u3044\u307e\u3057\u305f\u304c\u3001\u305d\u308d\u305d\u308d\u53f0\u6570\u7684\u306b\u9650\u754c\u306b\u81f3\u308a \u81ea\u52d5\u66f4\u65b0\u3059\u308b\u4ed5\u7d44\u307f\u3092\u30b5\u30af\u30c3\u3068\u4ee5\u4e0b\u306e\u8981\u4ef6\u3067\u4f5c\u6210\u3059\u308b [&hellip;]<\/p>\n","protected":false},"author":69,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27,43],"tags":[67],"_links":{"self":[{"href":"https:\/\/test.ecomottblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4283"}],"collection":[{"href":"https:\/\/test.ecomottblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/test.ecomottblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/test.ecomottblog.com\/index.php?rest_route=\/wp\/v2\/users\/69"}],"replies":[{"embeddable":true,"href":"https:\/\/test.ecomottblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4283"}],"version-history":[{"count":19,"href":"https:\/\/test.ecomottblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4283\/revisions"}],"predecessor-version":[{"id":4301,"href":"https:\/\/test.ecomottblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4283\/revisions\/4301"}],"wp:attachment":[{"href":"https:\/\/test.ecomottblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/test.ecomottblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/test.ecomottblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}