{"action":"created","comment":{"url":"https://api.github.com/repos/prometheus/alertmanager/pulls/comments/154069490","pull_request_review_id":80175086,"id":154069490,"diff_hunk":"@@ -0,0 +1,67 @@\n+package cli\n+\n+import (\n+\t\"os\"\n+\t\"io/ioutil\"\n+\t\"encoding/json\"\n+\t\"fmt\"\n+\n+\t\"github.com/prometheus/alertmanager/types\"\n+\t\"github.com/spf13/cobra\"\n+\t\"github.com/pkg/errors\"\n+)\n+\n+var importCmd = &cobra.Command{\n+\tUse:   \"import [JSON file]\",\n+\tShort: \"Import silences\",\n+\tLong: `Import alertmanager silences from JSON file or stdin\n+\n+  This command can be used to bulk import silences from a JSON file\n+  created by query command. For example:\n+\n+  amtool silence query -o json foo > foo.json\n+  amtool silence import foo.json\n+\n+  JSON data can also come from stdin if no param is specified.\n+\t`,\n+\tArgs: cobra.MaximumNArgs(1),\n+\tRun:  CommandWrapper(bulkImport),\n+}\n+\n+func bulkImport(cmd *cobra.Command, args []string) error {\n+\tinput := os.Stdin\n+\tvar err error\n+\n+\tif len(args) == 1 {\n+\t\tinput, err = os.Open(args[0])\n+\n+\t\tif err != nil {\n+\t\t\treturn err\n+\t\t}\n+\t}\n+\n+\tdata, err := ioutil.ReadAll(input)\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\n+\tvar silences []types.Silence\n+\terr = json.Unmarshal(data, &silences)\n+\tif err != nil {\n+\t\treturn errors.Wrap(err, \"couldn't unmarshal input data, is it in JSON?\")\n+\t}\n+\n+\tfor _, silence := range silences {\n+\t\t// reset the ID, otherwise alertmanager API will try to replace an existing silence\n+\t\t// this *might* create duplicated silences but that should generally be OK\n+\t\tsilence.ID = \"\"","path":"cli/silence_import.go","position":57,"original_position":57,"commit_id":"4f1ea40e55ba39fe04a466b1fa6e29bab22a17fb","original_commit_id":"4f1ea40e55ba39fe04a466b1fa6e29bab22a17fb","user":{"login":"josedonizetti","id":34032,"avatar_url":"https://avatars3.githubusercontent.com/u/34032?v=4","gravatar_id":"","url":"https://api.github.com/users/josedonizetti","html_url":"https://github.com/josedonizetti","followers_url":"https://api.github.com/users/josedonizetti/followers","following_url":"https://api.github.com/users/josedonizetti/following{/other_user}","gists_url":"https://api.github.com/users/josedonizetti/gists{/gist_id}","starred_url":"https://api.github.com/users/josedonizetti/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josedonizetti/subscriptions","organizations_url":"https://api.github.com/users/josedonizetti/orgs","repos_url":"https://api.github.com/users/josedonizetti/repos","events_url":"https://api.github.com/users/josedonizetti/events{/privacy}","received_events_url":"https://api.github.com/users/josedonizetti/received_events","type":"User","site_admin":false},"body":"Yeah, don't think we should have duplicated silences as well. Maybe skip the import if silence already exist? ","created_at":"2017-11-30T13:08:51Z","updated_at":"2017-11-30T13:08:51Z","html_url":"https://github.com/prometheus/alertmanager/pull/1082#discussion_r154069490","pull_request_url":"https://api.github.com/repos/prometheus/alertmanager/pulls/1082","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/prometheus/alertmanager/pulls/comments/154069490"},"html":{"href":"https://github.com/prometheus/alertmanager/pull/1082#discussion_r154069490"},"pull_request":{"href":"https://api.github.com/repos/prometheus/alertmanager/pulls/1082"}},"in_reply_to_id":149191410},"pull_request":{"url":"https://api.github.com/repos/prometheus/alertmanager/pulls/1082","id":150804537,"html_url":"https://github.com/prometheus/alertmanager/pull/1082","diff_url":"https://github.com/prometheus/alertmanager/pull/1082.diff","patch_url":"https://github.com/prometheus/alertmanager/pull/1082.patch","issue_url":"https://api.github.com/repos/prometheus/alertmanager/issues/1082","number":1082,"state":"open","locked":false,"title":"[amtool] - Add a new `silence import` command","user":{"login":"lebinh","id":234997,"avatar_url":"https://avatars2.githubusercontent.com/u/234997?v=4","gravatar_id":"","url":"https://api.github.com/users/lebinh","html_url":"https://github.com/lebinh","followers_url":"https://api.github.com/users/lebinh/followers","following_url":"https://api.github.com/users/lebinh/following{/other_user}","gists_url":"https://api.github.com/users/lebinh/gists{/gist_id}","starred_url":"https://api.github.com/users/lebinh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lebinh/subscriptions","organizations_url":"https://api.github.com/users/lebinh/orgs","repos_url":"https://api.github.com/users/lebinh/repos","events_url":"https://api.github.com/users/lebinh/events{/privacy}","received_events_url":"https://api.github.com/users/lebinh/received_events","type":"User","site_admin":false},"body":"This command read silences data from a query JSON output and import to\r\nalertmanager. It allows `amtool` to be used as a backup/restore tool for\r\nsilences, i.e. fix #1000\r\n\r\nBackup / export:\r\n\r\n```\r\namtool silence -o json > silences.json\r\n```\r\n\r\nRestore / import:\r\n\r\n```\r\namtool silence import silences.json\r\n```\r\n\r\nThis adds new silence one by one and will be slow if you have thousands of silences but alertmanager API doesn't allow multiple silences in POST so ¯\\\\_(ツ)_/¯","created_at":"2017-11-06T09:30:19Z","updated_at":"2017-11-30T13:08:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"16f38cd2f69f6a6bc22cde5500af2e45f8d937d6","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/prometheus/alertmanager/pulls/1082/commits","review_comments_url":"https://api.github.com/repos/prometheus/alertmanager/pulls/1082/comments","review_comment_url":"https://api.github.com/repos/prometheus/alertmanager/pulls/comments{/number}","comments_url":"https://api.github.com/repos/prometheus/alertmanager/issues/1082/comments","statuses_url":"https://api.github.com/repos/prometheus/alertmanager/statuses/4f1ea40e55ba39fe04a466b1fa6e29bab22a17fb","head":{"label":"lebinh:master","ref":"master","sha":"4f1ea40e55ba39fe04a466b1fa6e29bab22a17fb","user":{"login":"lebinh","id":234997,"avatar_url":"https://avatars2.githubusercontent.com/u/234997?v=4","gravatar_id":"","url":"https://api.github.com/users/lebinh","html_url":"https://github.com/lebinh","followers_url":"https://api.github.com/users/lebinh/followers","following_url":"https://api.github.com/users/lebinh/following{/other_user}","gists_url":"https://api.github.com/users/lebinh/gists{/gist_id}","starred_url":"https://api.github.com/users/lebinh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lebinh/subscriptions","organizations_url":"https://api.github.com/users/lebinh/orgs","repos_url":"https://api.github.com/users/lebinh/repos","events_url":"https://api.github.com/users/lebinh/events{/privacy}","received_events_url":"https://api.github.com/users/lebinh/received_events","type":"User","site_admin":false},"repo":{"id":109657556,"name":"alertmanager","full_name":"lebinh/alertmanager","owner":{"login":"lebinh","id":234997,"avatar_url":"https://avatars2.githubusercontent.com/u/234997?v=4","gravatar_id":"","url":"https://api.github.com/users/lebinh","html_url":"https://github.com/lebinh","followers_url":"https://api.github.com/users/lebinh/followers","following_url":"https://api.github.com/users/lebinh/following{/other_user}","gists_url":"https://api.github.com/users/lebinh/gists{/gist_id}","starred_url":"https://api.github.com/users/lebinh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lebinh/subscriptions","organizations_url":"https://api.github.com/users/lebinh/orgs","repos_url":"https://api.github.com/users/lebinh/repos","events_url":"https://api.github.com/users/lebinh/events{/privacy}","received_events_url":"https://api.github.com/users/lebinh/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/lebinh/alertmanager","description":"Prometheus Alertmanager","fork":true,"url":"https://api.github.com/repos/lebinh/alertmanager","forks_url":"https://api.github.com/repos/lebinh/alertmanager/forks","keys_url":"https://api.github.com/repos/lebinh/alertmanager/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lebinh/alertmanager/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lebinh/alertmanager/teams","hooks_url":"https://api.github.com/repos/lebinh/alertmanager/hooks","issue_events_url":"https://api.github.com/repos/lebinh/alertmanager/issues/events{/number}","events_url":"https://api.github.com/repos/lebinh/alertmanager/events","assignees_url":"https://api.github.com/repos/lebinh/alertmanager/assignees{/user}","branches_url":"https://api.github.com/repos/lebinh/alertmanager/branches{/branch}","tags_url":"https://api.github.com/repos/lebinh/alertmanager/tags","blobs_url":"https://api.github.com/repos/lebinh/alertmanager/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lebinh/alertmanager/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lebinh/alertmanager/git/refs{/sha}","trees_url":"https://api.github.com/repos/lebinh/alertmanager/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lebinh/alertmanager/statuses/{sha}","languages_url":"https://api.github.com/repos/lebinh/alertmanager/languages","stargazers_url":"https://api.github.com/repos/lebinh/alertmanager/stargazers","contributors_url":"https://api.github.com/repos/lebinh/alertmanager/contributors","subscribers_url":"https://api.github.com/repos/lebinh/alertmanager/subscribers","subscription_url":"https://api.github.com/repos/lebinh/alertmanager/subscription","commits_url":"https://api.github.com/repos/lebinh/alertmanager/commits{/sha}","git_commits_url":"https://api.github.com/repos/lebinh/alertmanager/git/commits{/sha}","comments_url":"https://api.github.com/repos/lebinh/alertmanager/comments{/number}","issue_comment_url":"https://api.github.com/repos/lebinh/alertmanager/issues/comments{/number}","contents_url":"https://api.github.com/repos/lebinh/alertmanager/contents/{+path}","compare_url":"https://api.github.com/repos/lebinh/alertmanager/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lebinh/alertmanager/merges","archive_url":"https://api.github.com/repos/lebinh/alertmanager/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lebinh/alertmanager/downloads","issues_url":"https://api.github.com/repos/lebinh/alertmanager/issues{/number}","pulls_url":"https://api.github.com/repos/lebinh/alertmanager/pulls{/number}","milestones_url":"https://api.github.com/repos/lebinh/alertmanager/milestones{/number}","notifications_url":"https://api.github.com/repos/lebinh/alertmanager/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lebinh/alertmanager/labels{/name}","releases_url":"https://api.github.com/repos/lebinh/alertmanager/releases{/id}","deployments_url":"https://api.github.com/repos/lebinh/alertmanager/deployments","created_at":"2017-11-06T06:43:24Z","updated_at":"2017-11-06T06:43:26Z","pushed_at":"2017-11-27T07:08:21Z","git_url":"git://github.com/lebinh/alertmanager.git","ssh_url":"git@github.com:lebinh/alertmanager.git","clone_url":"https://github.com/lebinh/alertmanager.git","svn_url":"https://github.com/lebinh/alertmanager","homepage":"","size":19149,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"prometheus:master","ref":"master","sha":"b9597f5c7b398b8e990fcbbc1e1715f73f84c683","user":{"login":"prometheus","id":3380462,"avatar_url":"https://avatars3.githubusercontent.com/u/3380462?v=4","gravatar_id":"","url":"https://api.github.com/users/prometheus","html_url":"https://github.com/prometheus","followers_url":"https://api.github.com/users/prometheus/followers","following_url":"https://api.github.com/users/prometheus/following{/other_user}","gists_url":"https://api.github.com/users/prometheus/gists{/gist_id}","starred_url":"https://api.github.com/users/prometheus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/prometheus/subscriptions","organizations_url":"https://api.github.com/users/prometheus/orgs","repos_url":"https://api.github.com/users/prometheus/repos","events_url":"https://api.github.com/users/prometheus/events{/privacy}","received_events_url":"https://api.github.com/users/prometheus/received_events","type":"Organization","site_admin":false},"repo":{"id":11452538,"name":"alertmanager","full_name":"prometheus/alertmanager","owner":{"login":"prometheus","id":3380462,"avatar_url":"https://avatars3.githubusercontent.com/u/3380462?v=4","gravatar_id":"","url":"https://api.github.com/users/prometheus","html_url":"https://github.com/prometheus","followers_url":"https://api.github.com/users/prometheus/followers","following_url":"https://api.github.com/users/prometheus/following{/other_user}","gists_url":"https://api.github.com/users/prometheus/gists{/gist_id}","starred_url":"https://api.github.com/users/prometheus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/prometheus/subscriptions","organizations_url":"https://api.github.com/users/prometheus/orgs","repos_url":"https://api.github.com/users/prometheus/repos","events_url":"https://api.github.com/users/prometheus/events{/privacy}","received_events_url":"https://api.github.com/users/prometheus/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/prometheus/alertmanager","description":"Prometheus Alertmanager","fork":false,"url":"https://api.github.com/repos/prometheus/alertmanager","forks_url":"https://api.github.com/repos/prometheus/alertmanager/forks","keys_url":"https://api.github.com/repos/prometheus/alertmanager/keys{/key_id}","collaborators_url":"https://api.github.com/repos/prometheus/alertmanager/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/prometheus/alertmanager/teams","hooks_url":"https://api.github.com/repos/prometheus/alertmanager/hooks","issue_events_url":"https://api.github.com/repos/prometheus/alertmanager/issues/events{/number}","events_url":"https://api.github.com/repos/prometheus/alertmanager/events","assignees_url":"https://api.github.com/repos/prometheus/alertmanager/assignees{/user}","branches_url":"https://api.github.com/repos/prometheus/alertmanager/branches{/branch}","tags_url":"https://api.github.com/repos/prometheus/alertmanager/tags","blobs_url":"https://api.github.com/repos/prometheus/alertmanager/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/prometheus/alertmanager/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/prometheus/alertmanager/git/refs{/sha}","trees_url":"https://api.github.com/repos/prometheus/alertmanager/git/trees{/sha}","statuses_url":"https://api.github.com/repos/prometheus/alertmanager/statuses/{sha}","languages_url":"https://api.github.com/repos/prometheus/alertmanager/languages","stargazers_url":"https://api.github.com/repos/prometheus/alertmanager/stargazers","contributors_url":"https://api.github.com/repos/prometheus/alertmanager/contributors","subscribers_url":"https://api.github.com/repos/prometheus/alertmanager/subscribers","subscription_url":"https://api.github.com/repos/prometheus/alertmanager/subscription","commits_url":"https://api.github.com/repos/prometheus/alertmanager/commits{/sha}","git_commits_url":"https://api.github.com/repos/prometheus/alertmanager/git/commits{/sha}","comments_url":"https://api.github.com/repos/prometheus/alertmanager/comments{/number}","issue_comment_url":"https://api.github.com/repos/prometheus/alertmanager/issues/comments{/number}","contents_url":"https://api.github.com/repos/prometheus/alertmanager/contents/{+path}","compare_url":"https://api.github.com/repos/prometheus/alertmanager/compare/{base}...{head}","merges_url":"https://api.github.com/repos/prometheus/alertmanager/merges","archive_url":"https://api.github.com/repos/prometheus/alertmanager/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/prometheus/alertmanager/downloads","issues_url":"https://api.github.com/repos/prometheus/alertmanager/issues{/number}","pulls_url":"https://api.github.com/repos/prometheus/alertmanager/pulls{/number}","milestones_url":"https://api.github.com/repos/prometheus/alertmanager/milestones{/number}","notifications_url":"https://api.github.com/repos/prometheus/alertmanager/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/prometheus/alertmanager/labels{/name}","releases_url":"https://api.github.com/repos/prometheus/alertmanager/releases{/id}","deployments_url":"https://api.github.com/repos/prometheus/alertmanager/deployments","created_at":"2013-07-16T15:06:31Z","updated_at":"2017-11-30T10:37:16Z","pushed_at":"2017-11-27T11:00:32Z","git_url":"git://github.com/prometheus/alertmanager.git","ssh_url":"git@github.com:prometheus/alertmanager.git","clone_url":"https://github.com/prometheus/alertmanager.git","svn_url":"https://github.com/prometheus/alertmanager","homepage":"","size":19388,"stargazers_count":833,"watchers_count":833,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":356,"mirror_url":null,"archived":false,"open_issues_count":141,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":356,"open_issues":141,"watchers":833,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/prometheus/alertmanager/pulls/1082"},"html":{"href":"https://github.com/prometheus/alertmanager/pull/1082"},"issue":{"href":"https://api.github.com/repos/prometheus/alertmanager/issues/1082"},"comments":{"href":"https://api.github.com/repos/prometheus/alertmanager/issues/1082/comments"},"review_comments":{"href":"https://api.github.com/repos/prometheus/alertmanager/pulls/1082/comments"},"review_comment":{"href":"https://api.github.com/repos/prometheus/alertmanager/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/prometheus/alertmanager/pulls/1082/commits"},"statuses":{"href":"https://api.github.com/repos/prometheus/alertmanager/statuses/4f1ea40e55ba39fe04a466b1fa6e29bab22a17fb"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"josedonizetti"}}