{"action":"created","comment":{"url":"https://api.github.com/repos/elastic/beats/pulls/comments/60223986","id":60223986,"diff_hunk":"@@ -48,46 +61,97 @@ func (m *MetricSeter) Setup(ms *helper.MetricSet) error {\n \t\treturn err\n \t}\n \n-\tm.ServerStatusPath = config.ServerStatusPath\n-\tm.Username = config.Username\n-\tm.Password = config.Password\n-\tif m.Password != \"\" && m.Username != \"\" {\n-\t\tm.Authentication = true\n-\t} else {\n-\t\tm.Authentication = false\n+\tm.URLs = make(map[string]string, len(ms.Config.Hosts))\n+\n+\t// Parse the config, create URLs, and check for errors.\n+\tvar errs multierror.Errors\n+\tfor _, host := range ms.Config.Hosts {\n+\t\tu, err := getURL(config.Username, config.Password, config.ServerStatusPath, host)\n+\t\tif err != nil {\n+\t\t\terrs = append(errs, err)\n+\t\t\tcontinue\n+\t\t}\n+\t\tm.URLs[host] = u.String()\n+\t\tdebugf(\"apache-status URL=%s\", redactPassword(*u))\n \t}\n \n-\treturn nil\n+\treturn errs.Err()\n }\n \n+// Fetch makes an HTTP request to fetch status metrics from the mod_status\n+// endpoint.\n func (m *MetricSeter) Fetch(ms *helper.MetricSet, host string) (event common.MapStr, err error) {\n+\turl, ok := m.URLs[host]\n+\tif !ok {\n+\t\treturn nil, fmt.Errorf(\"url not found for host '%s'\", host)\n+\t}\n \n-\tu, err := url.Parse(host + m.ServerStatusPath)\n+\treq, err := http.NewRequest(\"GET\", url, nil)\n+\tclient := &http.Client{}\n+\tresp, err := client.Do(req)\n \tif err != nil {\n-\t\tlogp.Err(\"Invalid Apache HTTPD server-status page: %v\", err)\n-\t\treturn nil, err\n+\t\treturn nil, fmt.Errorf(\"error making HTTP request: %v\", err)\n \t}\n+\tdefer resp.Body.Close()","path":"metricbeat/module/apache/status/status.go","position":111,"original_position":111,"commit_id":"0961fa5cbe1023ceaa7418a1a8bbb23d7c788d4a","original_commit_id":"0961fa5cbe1023ceaa7418a1a8bbb23d7c788d4a","user":{"login":"andrewkroh","id":4565752,"avatar_url":"https://avatars.githubusercontent.com/u/4565752?v=3","gravatar_id":"","url":"https://api.github.com/users/andrewkroh","html_url":"https://github.com/andrewkroh","followers_url":"https://api.github.com/users/andrewkroh/followers","following_url":"https://api.github.com/users/andrewkroh/following{/other_user}","gists_url":"https://api.github.com/users/andrewkroh/gists{/gist_id}","starred_url":"https://api.github.com/users/andrewkroh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrewkroh/subscriptions","organizations_url":"https://api.github.com/users/andrewkroh/orgs","repos_url":"https://api.github.com/users/andrewkroh/repos","events_url":"https://api.github.com/users/andrewkroh/events{/privacy}","received_events_url":"https://api.github.com/users/andrewkroh/received_events","type":"User","site_admin":false},"body":"According to the docs for [`client.Do()`](https://golang.org/pkg/net/http/#Client.Do), when err is nil, `resp` always contains a non-nil `resp.Body`. So `defer resp.Body.Close()` should come after the err check to prevent a nil pointer deference no `resp`.","created_at":"2016-04-19T12:51:15Z","updated_at":"2016-04-19T12:51:15Z","html_url":"https://github.com/elastic/beats/pull/1413#discussion_r60223986","pull_request_url":"https://api.github.com/repos/elastic/beats/pulls/1413","_links":{"self":{"href":"https://api.github.com/repos/elastic/beats/pulls/comments/60223986"},"html":{"href":"https://github.com/elastic/beats/pull/1413#discussion_r60223986"},"pull_request":{"href":"https://api.github.com/repos/elastic/beats/pulls/1413"}}},"pull_request":{"url":"https://api.github.com/repos/elastic/beats/pulls/1413","id":66918248,"html_url":"https://github.com/elastic/beats/pull/1413","diff_url":"https://github.com/elastic/beats/pull/1413.diff","patch_url":"https://github.com/elastic/beats/pull/1413.patch","issue_url":"https://api.github.com/repos/elastic/beats/issues/1413","number":1413,"state":"closed","locked":false,"title":"Add apache-status system test for Metricbeat","user":{"login":"andrewkroh","id":4565752,"avatar_url":"https://avatars.githubusercontent.com/u/4565752?v=3","gravatar_id":"","url":"https://api.github.com/users/andrewkroh","html_url":"https://github.com/andrewkroh","followers_url":"https://api.github.com/users/andrewkroh/followers","following_url":"https://api.github.com/users/andrewkroh/following{/other_user}","gists_url":"https://api.github.com/users/andrewkroh/gists{/gist_id}","starred_url":"https://api.github.com/users/andrewkroh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrewkroh/subscriptions","organizations_url":"https://api.github.com/users/andrewkroh/orgs","repos_url":"https://api.github.com/users/andrewkroh/repos","events_url":"https://api.github.com/users/andrewkroh/events{/privacy}","received_events_url":"https://api.github.com/users/andrewkroh/received_events","type":"User","site_admin":false},"body":"Improve host config parsing for apache-status metricset.\r\nDocument common fields in fields.yml.","created_at":"2016-04-18T20:40:57Z","updated_at":"2016-04-19T12:51:15Z","closed_at":"2016-04-19T05:58:42Z","merged_at":"2016-04-19T05:58:42Z","merge_commit_sha":"7ec837fdac7039262ee4d0b7cb7ad923a43cc71d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/elastic/beats/pulls/1413/commits","review_comments_url":"https://api.github.com/repos/elastic/beats/pulls/1413/comments","review_comment_url":"https://api.github.com/repos/elastic/beats/pulls/comments{/number}","comments_url":"https://api.github.com/repos/elastic/beats/issues/1413/comments","statuses_url":"https://api.github.com/repos/elastic/beats/statuses/0961fa5cbe1023ceaa7418a1a8bbb23d7c788d4a","head":{"label":"andrewkroh:feature/apache-status-tests","ref":"feature/apache-status-tests","sha":"0961fa5cbe1023ceaa7418a1a8bbb23d7c788d4a","user":{"login":"andrewkroh","id":4565752,"avatar_url":"https://avatars.githubusercontent.com/u/4565752?v=3","gravatar_id":"","url":"https://api.github.com/users/andrewkroh","html_url":"https://github.com/andrewkroh","followers_url":"https://api.github.com/users/andrewkroh/followers","following_url":"https://api.github.com/users/andrewkroh/following{/other_user}","gists_url":"https://api.github.com/users/andrewkroh/gists{/gist_id}","starred_url":"https://api.github.com/users/andrewkroh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrewkroh/subscriptions","organizations_url":"https://api.github.com/users/andrewkroh/orgs","repos_url":"https://api.github.com/users/andrewkroh/repos","events_url":"https://api.github.com/users/andrewkroh/events{/privacy}","received_events_url":"https://api.github.com/users/andrewkroh/received_events","type":"User","site_admin":false},"repo":{"id":38412372,"name":"beats","full_name":"andrewkroh/beats","owner":{"login":"andrewkroh","id":4565752,"avatar_url":"https://avatars.githubusercontent.com/u/4565752?v=3","gravatar_id":"","url":"https://api.github.com/users/andrewkroh","html_url":"https://github.com/andrewkroh","followers_url":"https://api.github.com/users/andrewkroh/followers","following_url":"https://api.github.com/users/andrewkroh/following{/other_user}","gists_url":"https://api.github.com/users/andrewkroh/gists{/gist_id}","starred_url":"https://api.github.com/users/andrewkroh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrewkroh/subscriptions","organizations_url":"https://api.github.com/users/andrewkroh/orgs","repos_url":"https://api.github.com/users/andrewkroh/repos","events_url":"https://api.github.com/users/andrewkroh/events{/privacy}","received_events_url":"https://api.github.com/users/andrewkroh/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/andrewkroh/beats","description":"Beats - Lightweight shippers for Elasticsearch & Logstash ","fork":true,"url":"https://api.github.com/repos/andrewkroh/beats","forks_url":"https://api.github.com/repos/andrewkroh/beats/forks","keys_url":"https://api.github.com/repos/andrewkroh/beats/keys{/key_id}","collaborators_url":"https://api.github.com/repos/andrewkroh/beats/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/andrewkroh/beats/teams","hooks_url":"https://api.github.com/repos/andrewkroh/beats/hooks","issue_events_url":"https://api.github.com/repos/andrewkroh/beats/issues/events{/number}","events_url":"https://api.github.com/repos/andrewkroh/beats/events","assignees_url":"https://api.github.com/repos/andrewkroh/beats/assignees{/user}","branches_url":"https://api.github.com/repos/andrewkroh/beats/branches{/branch}","tags_url":"https://api.github.com/repos/andrewkroh/beats/tags","blobs_url":"https://api.github.com/repos/andrewkroh/beats/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/andrewkroh/beats/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/andrewkroh/beats/git/refs{/sha}","trees_url":"https://api.github.com/repos/andrewkroh/beats/git/trees{/sha}","statuses_url":"https://api.github.com/repos/andrewkroh/beats/statuses/{sha}","languages_url":"https://api.github.com/repos/andrewkroh/beats/languages","stargazers_url":"https://api.github.com/repos/andrewkroh/beats/stargazers","contributors_url":"https://api.github.com/repos/andrewkroh/beats/contributors","subscribers_url":"https://api.github.com/repos/andrewkroh/beats/subscribers","subscription_url":"https://api.github.com/repos/andrewkroh/beats/subscription","commits_url":"https://api.github.com/repos/andrewkroh/beats/commits{/sha}","git_commits_url":"https://api.github.com/repos/andrewkroh/beats/git/commits{/sha}","comments_url":"https://api.github.com/repos/andrewkroh/beats/comments{/number}","issue_comment_url":"https://api.github.com/repos/andrewkroh/beats/issues/comments{/number}","contents_url":"https://api.github.com/repos/andrewkroh/beats/contents/{+path}","compare_url":"https://api.github.com/repos/andrewkroh/beats/compare/{base}...{head}","merges_url":"https://api.github.com/repos/andrewkroh/beats/merges","archive_url":"https://api.github.com/repos/andrewkroh/beats/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/andrewkroh/beats/downloads","issues_url":"https://api.github.com/repos/andrewkroh/beats/issues{/number}","pulls_url":"https://api.github.com/repos/andrewkroh/beats/pulls{/number}","milestones_url":"https://api.github.com/repos/andrewkroh/beats/milestones{/number}","notifications_url":"https://api.github.com/repos/andrewkroh/beats/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/andrewkroh/beats/labels{/name}","releases_url":"https://api.github.com/repos/andrewkroh/beats/releases{/id}","deployments_url":"https://api.github.com/repos/andrewkroh/beats/deployments","created_at":"2015-07-02T05:03:11Z","updated_at":"2016-01-20T19:52:45Z","pushed_at":"2016-04-19T01:08:54Z","git_url":"git://github.com/andrewkroh/beats.git","ssh_url":"git@github.com:andrewkroh/beats.git","clone_url":"https://github.com/andrewkroh/beats.git","svn_url":"https://github.com/andrewkroh/beats","homepage":"https://www.elastic.co/products/beats","size":28156,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"elastic:master","ref":"master","sha":"35d5dc9406619bc369f4075a788834eff47f8844","user":{"login":"elastic","id":6764390,"avatar_url":"https://avatars.githubusercontent.com/u/6764390?v=3","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"repo":{"id":16554739,"name":"beats","full_name":"elastic/beats","owner":{"login":"elastic","id":6764390,"avatar_url":"https://avatars.githubusercontent.com/u/6764390?v=3","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/elastic/beats","description":"Beats - Lightweight shippers for Elasticsearch & Logstash ","fork":false,"url":"https://api.github.com/repos/elastic/beats","forks_url":"https://api.github.com/repos/elastic/beats/forks","keys_url":"https://api.github.com/repos/elastic/beats/keys{/key_id}","collaborators_url":"https://api.github.com/repos/elastic/beats/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/elastic/beats/teams","hooks_url":"https://api.github.com/repos/elastic/beats/hooks","issue_events_url":"https://api.github.com/repos/elastic/beats/issues/events{/number}","events_url":"https://api.github.com/repos/elastic/beats/events","assignees_url":"https://api.github.com/repos/elastic/beats/assignees{/user}","branches_url":"https://api.github.com/repos/elastic/beats/branches{/branch}","tags_url":"https://api.github.com/repos/elastic/beats/tags","blobs_url":"https://api.github.com/repos/elastic/beats/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/elastic/beats/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/elastic/beats/git/refs{/sha}","trees_url":"https://api.github.com/repos/elastic/beats/git/trees{/sha}","statuses_url":"https://api.github.com/repos/elastic/beats/statuses/{sha}","languages_url":"https://api.github.com/repos/elastic/beats/languages","stargazers_url":"https://api.github.com/repos/elastic/beats/stargazers","contributors_url":"https://api.github.com/repos/elastic/beats/contributors","subscribers_url":"https://api.github.com/repos/elastic/beats/subscribers","subscription_url":"https://api.github.com/repos/elastic/beats/subscription","commits_url":"https://api.github.com/repos/elastic/beats/commits{/sha}","git_commits_url":"https://api.github.com/repos/elastic/beats/git/commits{/sha}","comments_url":"https://api.github.com/repos/elastic/beats/comments{/number}","issue_comment_url":"https://api.github.com/repos/elastic/beats/issues/comments{/number}","contents_url":"https://api.github.com/repos/elastic/beats/contents/{+path}","compare_url":"https://api.github.com/repos/elastic/beats/compare/{base}...{head}","merges_url":"https://api.github.com/repos/elastic/beats/merges","archive_url":"https://api.github.com/repos/elastic/beats/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/elastic/beats/downloads","issues_url":"https://api.github.com/repos/elastic/beats/issues{/number}","pulls_url":"https://api.github.com/repos/elastic/beats/pulls{/number}","milestones_url":"https://api.github.com/repos/elastic/beats/milestones{/number}","notifications_url":"https://api.github.com/repos/elastic/beats/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/elastic/beats/labels{/name}","releases_url":"https://api.github.com/repos/elastic/beats/releases{/id}","deployments_url":"https://api.github.com/repos/elastic/beats/deployments","created_at":"2014-02-05T19:01:02Z","updated_at":"2016-04-19T12:17:14Z","pushed_at":"2016-04-19T12:48:04Z","git_url":"git://github.com/elastic/beats.git","ssh_url":"git@github.com:elastic/beats.git","clone_url":"https://github.com/elastic/beats.git","svn_url":"https://github.com/elastic/beats","homepage":"https://www.elastic.co/products/beats","size":33268,"stargazers_count":2639,"watchers_count":2639,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":392,"mirror_url":null,"open_issues_count":232,"forks":392,"open_issues":232,"watchers":2639,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/elastic/beats/pulls/1413"},"html":{"href":"https://github.com/elastic/beats/pull/1413"},"issue":{"href":"https://api.github.com/repos/elastic/beats/issues/1413"},"comments":{"href":"https://api.github.com/repos/elastic/beats/issues/1413/comments"},"review_comments":{"href":"https://api.github.com/repos/elastic/beats/pulls/1413/comments"},"review_comment":{"href":"https://api.github.com/repos/elastic/beats/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/elastic/beats/pulls/1413/commits"},"statuses":{"href":"https://api.github.com/repos/elastic/beats/statuses/0961fa5cbe1023ceaa7418a1a8bbb23d7c788d4a"}}}}