{"action":"created","comment":{"url":"https://api.github.com/repos/bosun-monitor/bosun/pulls/comments/42585240","id":42585240,"diff_hunk":"@@ -0,0 +1,405 @@\n+package collectors\n+\n+import (\n+\t\"bytes\"\n+\t\"crypto/tls\"\n+\t\"encoding/json\"\n+\t\"encoding/xml\"\n+\t\"fmt\"\n+\t\"io/ioutil\"\n+\t\"net/http\"\n+\t\"net/url\"\n+\t\"strings\"\n+\t\"time\"\n+\n+\t\"bosun.org/cmd/scollector/conf\"\n+\t\"bosun.org/metadata\"\n+\t\"bosun.org/opentsdb\"\n+)\n+\n+type loginRequest struct {\n+\tXMLName  xml.Name `xml:\"LoginRequest\"`\n+\tUserID   string   `xml:\"user-id,attr\"`\n+\tPassword string   `xml:\"password,attr\"`\n+}\n+\n+type apiResponse struct {\n+\tXMLName       xml.Name\n+\tMessage       string        `xml:\"Message\"`\n+\tSessionID     string        `xml:\"session-id,attr\"`\n+\tSiteSummaries []siteSummary `xml:\"SiteSummary\"`\n+\tScanSummaries []scanSummary `xml:\"ScanSummary\"`\n+\tDevices       []device      `xml:\"SiteDevices>device\"`\n+}\n+\n+type simpleRequest struct {\n+\tXMLName   xml.Name\n+\tSessionID string `xml:\"session-id,attr\"`\n+}\n+\n+type siteRequest struct {\n+\tXMLName   xml.Name\n+\tSessionID string `xml:\"session-id,attr\"`\n+\tSiteID    int    `xml:\"site-id,attr\"`\n+}\n+\n+type siteSummary struct {\n+\tID           int     `xml:\"id,attr\"`\n+\tName         string  `xml:\"name,attr\"`\n+\tDescription  string  `xml:\"description,attr\"`\n+\tRiskFactor   float32 `xml:\"riskfactor,attr\"`\n+\tRiskScore    float64 `xml:\"riskscore,attr\"`\n+\tExploitCount int\n+\tMalwareCount int\n+\tVulnCount    int\n+}\n+\n+type device struct {\n+\tID         int     `xml:\"id,attr\"`\n+\tAddress    string  `xml:\"address,attr\"`\n+\tRiskFactor float32 `xml:\"riskfactor,attr\"`\n+\tRiskScore  float64 `xml:\"riskscore,attr\"`\n+}\n+\n+type scanSummary struct {\n+\tID        int    `xml:\"scan-id,attr\"`\n+\tSiteID    int    `xml:\"site-id,attr\"`\n+\tEngineID  int    `xml:\"engine-id,attr\"`\n+\tName      string `xml:\"name,attr\"`\n+\tStartTime string `xml:\"startTime,attr\"`\n+\tEndTime   string `xml:\"endTime,attr\"`\n+\tStatus    string `xml:\"status,attr\"`\n+}\n+\n+func init() {\n+\tregisterInit(func(c *conf.Conf) {\n+\t\tfor _, n := range c.Nexpose {\n+\t\t\tcollectors = append(collectors, &IntervalCollector{\n+\t\t\t\tF: func() (opentsdb.MultiDataPoint, error) {\n+\t\t\t\t\treturn c_nexpose(n.Username, n.Password, n.Host, n.Insecure)\n+\t\t\t\t},\n+\t\t\t\tname: fmt.Sprintf(\"nexpose-%s\", n.Host),\n+\t\t\t})\n+\t\t}\n+\t})\n+}\n+\n+type nexposeConnection struct {\n+\tUsername  string\n+\tPassword  string\n+\tHost      string\n+\tURLv1     string\n+\tURLv2     string\n+\tClient    *http.Client\n+\tSessionID string\n+\tCookie    *http.Cookie\n+}\n+\n+func c_nexpose(username, password, host string, insecure bool) (opentsdb.MultiDataPoint, error) {\n+\ttr := &http.Transport{\n+\t\tTLSClientConfig: &tls.Config{InsecureSkipVerify: insecure},\n+\t}\n+\tclient := &http.Client{Transport: tr}\n+\turl1 := fmt.Sprintf(\"https://%s/api/1.1/xml\", host)\n+\turl2 := fmt.Sprintf(\"https://%s/api/1.2/xml\", host)\n+\n+\tvar md opentsdb.MultiDataPoint\n+\n+\tc := nexposeConnection{Username: username, Password: password, URLv1: url1, URLv2: url2, Host: host, Client: client}\n+\n+\terr := c.login()","path":"cmd/scollector/collectors/nexpose.go","position":110,"original_position":110,"commit_id":"c276510886f85c9c072df08c86aebcfe7e6c8e75","original_commit_id":"c276510886f85c9c072df08c86aebcfe7e6c8e75","user":{"login":"captncraig","id":192540,"avatar_url":"https://avatars.githubusercontent.com/u/192540?v=3","gravatar_id":"","url":"https://api.github.com/users/captncraig","html_url":"https://github.com/captncraig","followers_url":"https://api.github.com/users/captncraig/followers","following_url":"https://api.github.com/users/captncraig/following{/other_user}","gists_url":"https://api.github.com/users/captncraig/gists{/gist_id}","starred_url":"https://api.github.com/users/captncraig/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/captncraig/subscriptions","organizations_url":"https://api.github.com/users/captncraig/orgs","repos_url":"https://api.github.com/users/captncraig/repos","events_url":"https://api.github.com/users/captncraig/events{/privacy}","received_events_url":"https://api.github.com/users/captncraig/received_events","type":"User","site_admin":false},"body":"you can condense a lot of these to the inline if format:\r\n```\r\nif err := c.Login(); err != nil{\r\n    return nil, fmt.Errorf(\"Login failed: %s\", err)\r\n}\r\n```","created_at":"2015-10-21T05:48:23Z","updated_at":"2015-10-21T05:48:23Z","html_url":"https://github.com/bosun-monitor/bosun/pull/1407#discussion_r42585240","pull_request_url":"https://api.github.com/repos/bosun-monitor/bosun/pulls/1407","_links":{"self":{"href":"https://api.github.com/repos/bosun-monitor/bosun/pulls/comments/42585240"},"html":{"href":"https://github.com/bosun-monitor/bosun/pull/1407#discussion_r42585240"},"pull_request":{"href":"https://api.github.com/repos/bosun-monitor/bosun/pulls/1407"}}},"pull_request":{"url":"https://api.github.com/repos/bosun-monitor/bosun/pulls/1407","id":48270973,"html_url":"https://github.com/bosun-monitor/bosun/pull/1407","diff_url":"https://github.com/bosun-monitor/bosun/pull/1407.diff","patch_url":"https://github.com/bosun-monitor/bosun/pull/1407.patch","issue_url":"https://api.github.com/repos/bosun-monitor/bosun/issues/1407","number":1407,"state":"open","locked":false,"title":"Add nexpose collector.","user":{"login":"alienth","id":218431,"avatar_url":"https://avatars.githubusercontent.com/u/218431?v=3","gravatar_id":"","url":"https://api.github.com/users/alienth","html_url":"https://github.com/alienth","followers_url":"https://api.github.com/users/alienth/followers","following_url":"https://api.github.com/users/alienth/following{/other_user}","gists_url":"https://api.github.com/users/alienth/gists{/gist_id}","starred_url":"https://api.github.com/users/alienth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alienth/subscriptions","organizations_url":"https://api.github.com/users/alienth/orgs","repos_url":"https://api.github.com/users/alienth/repos","events_url":"https://api.github.com/users/alienth/events{/privacy}","received_events_url":"https://api.github.com/users/alienth/received_events","type":"User","site_admin":false},"body":"Looking for an initial review pass on this collector.\r\n\r\nCollector is configured as follows:\r\n\r\n```\r\n[[Nexpose]]\r\nUsername = \"nexposeacct\"\r\nPassword = \"nexposesucks\"\r\nHost = \"nexposehost.blah.com\"\r\nInsecure = false\r\n```\r\n\r\nFor each monitored asset, it sends metrics with the vuln count, malware count, risk score, exploit count, and last scan time (represented in seconds since last scan). The asset `name` is either the detected hostname, or the IP address of the host.\r\n\r\nFor each site, it sends `nexpose.site` metrics which are an aggregate of the aforementioned device metrics.\r\n\r\nIt also sends a `nexpose.scan.running` metric indicating if a scan is currently running on a site.\r\n\r\n\r\nNote that not all of the defined functions are used at this time. They'll probably come in handy for other metrics, so I'd like to keep em in. I'll probably end up creating a generic Go package for nexpose and rip a lot of that stuff out of this collector.\r\n\r\n\r\n:eyeglasses: @kylebrandt @captncraig \r\n","created_at":"2015-10-20T23:23:14Z","updated_at":"2015-10-21T05:48:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a32eb5e6423e0ff09f5520695c69465cb5182120","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/bosun-monitor/bosun/pulls/1407/commits","review_comments_url":"https://api.github.com/repos/bosun-monitor/bosun/pulls/1407/comments","review_comment_url":"https://api.github.com/repos/bosun-monitor/bosun/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bosun-monitor/bosun/issues/1407/comments","statuses_url":"https://api.github.com/repos/bosun-monitor/bosun/statuses/c276510886f85c9c072df08c86aebcfe7e6c8e75","head":{"label":"alienth:nexpose","ref":"nexpose","sha":"c276510886f85c9c072df08c86aebcfe7e6c8e75","user":{"login":"alienth","id":218431,"avatar_url":"https://avatars.githubusercontent.com/u/218431?v=3","gravatar_id":"","url":"https://api.github.com/users/alienth","html_url":"https://github.com/alienth","followers_url":"https://api.github.com/users/alienth/followers","following_url":"https://api.github.com/users/alienth/following{/other_user}","gists_url":"https://api.github.com/users/alienth/gists{/gist_id}","starred_url":"https://api.github.com/users/alienth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alienth/subscriptions","organizations_url":"https://api.github.com/users/alienth/orgs","repos_url":"https://api.github.com/users/alienth/repos","events_url":"https://api.github.com/users/alienth/events{/privacy}","received_events_url":"https://api.github.com/users/alienth/received_events","type":"User","site_admin":false},"repo":{"id":31330003,"name":"bosun","full_name":"alienth/bosun","owner":{"login":"alienth","id":218431,"avatar_url":"https://avatars.githubusercontent.com/u/218431?v=3","gravatar_id":"","url":"https://api.github.com/users/alienth","html_url":"https://github.com/alienth","followers_url":"https://api.github.com/users/alienth/followers","following_url":"https://api.github.com/users/alienth/following{/other_user}","gists_url":"https://api.github.com/users/alienth/gists{/gist_id}","starred_url":"https://api.github.com/users/alienth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alienth/subscriptions","organizations_url":"https://api.github.com/users/alienth/orgs","repos_url":"https://api.github.com/users/alienth/repos","events_url":"https://api.github.com/users/alienth/events{/privacy}","received_events_url":"https://api.github.com/users/alienth/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/alienth/bosun","description":"Time Series Alerting Framework","fork":true,"url":"https://api.github.com/repos/alienth/bosun","forks_url":"https://api.github.com/repos/alienth/bosun/forks","keys_url":"https://api.github.com/repos/alienth/bosun/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alienth/bosun/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alienth/bosun/teams","hooks_url":"https://api.github.com/repos/alienth/bosun/hooks","issue_events_url":"https://api.github.com/repos/alienth/bosun/issues/events{/number}","events_url":"https://api.github.com/repos/alienth/bosun/events","assignees_url":"https://api.github.com/repos/alienth/bosun/assignees{/user}","branches_url":"https://api.github.com/repos/alienth/bosun/branches{/branch}","tags_url":"https://api.github.com/repos/alienth/bosun/tags","blobs_url":"https://api.github.com/repos/alienth/bosun/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alienth/bosun/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alienth/bosun/git/refs{/sha}","trees_url":"https://api.github.com/repos/alienth/bosun/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alienth/bosun/statuses/{sha}","languages_url":"https://api.github.com/repos/alienth/bosun/languages","stargazers_url":"https://api.github.com/repos/alienth/bosun/stargazers","contributors_url":"https://api.github.com/repos/alienth/bosun/contributors","subscribers_url":"https://api.github.com/repos/alienth/bosun/subscribers","subscription_url":"https://api.github.com/repos/alienth/bosun/subscription","commits_url":"https://api.github.com/repos/alienth/bosun/commits{/sha}","git_commits_url":"https://api.github.com/repos/alienth/bosun/git/commits{/sha}","comments_url":"https://api.github.com/repos/alienth/bosun/comments{/number}","issue_comment_url":"https://api.github.com/repos/alienth/bosun/issues/comments{/number}","contents_url":"https://api.github.com/repos/alienth/bosun/contents/{+path}","compare_url":"https://api.github.com/repos/alienth/bosun/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alienth/bosun/merges","archive_url":"https://api.github.com/repos/alienth/bosun/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alienth/bosun/downloads","issues_url":"https://api.github.com/repos/alienth/bosun/issues{/number}","pulls_url":"https://api.github.com/repos/alienth/bosun/pulls{/number}","milestones_url":"https://api.github.com/repos/alienth/bosun/milestones{/number}","notifications_url":"https://api.github.com/repos/alienth/bosun/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alienth/bosun/labels{/name}","releases_url":"https://api.github.com/repos/alienth/bosun/releases{/id}","created_at":"2015-02-25T18:47:51Z","updated_at":"2015-04-29T20:49:09Z","pushed_at":"2015-10-20T23:17:36Z","git_url":"git://github.com/alienth/bosun.git","ssh_url":"git@github.com:alienth/bosun.git","clone_url":"https://github.com/alienth/bosun.git","svn_url":"https://github.com/alienth/bosun","homepage":"http://bosun.org","size":23689,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"bosun-monitor:master","ref":"master","sha":"f4e866e1686ec1329e2ea0374c12b28fb065a698","user":{"login":"bosun-monitor","id":9555242,"avatar_url":"https://avatars.githubusercontent.com/u/9555242?v=3","gravatar_id":"","url":"https://api.github.com/users/bosun-monitor","html_url":"https://github.com/bosun-monitor","followers_url":"https://api.github.com/users/bosun-monitor/followers","following_url":"https://api.github.com/users/bosun-monitor/following{/other_user}","gists_url":"https://api.github.com/users/bosun-monitor/gists{/gist_id}","starred_url":"https://api.github.com/users/bosun-monitor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bosun-monitor/subscriptions","organizations_url":"https://api.github.com/users/bosun-monitor/orgs","repos_url":"https://api.github.com/users/bosun-monitor/repos","events_url":"https://api.github.com/users/bosun-monitor/events{/privacy}","received_events_url":"https://api.github.com/users/bosun-monitor/received_events","type":"Organization","site_admin":false},"repo":{"id":14410778,"name":"bosun","full_name":"bosun-monitor/bosun","owner":{"login":"bosun-monitor","id":9555242,"avatar_url":"https://avatars.githubusercontent.com/u/9555242?v=3","gravatar_id":"","url":"https://api.github.com/users/bosun-monitor","html_url":"https://github.com/bosun-monitor","followers_url":"https://api.github.com/users/bosun-monitor/followers","following_url":"https://api.github.com/users/bosun-monitor/following{/other_user}","gists_url":"https://api.github.com/users/bosun-monitor/gists{/gist_id}","starred_url":"https://api.github.com/users/bosun-monitor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bosun-monitor/subscriptions","organizations_url":"https://api.github.com/users/bosun-monitor/orgs","repos_url":"https://api.github.com/users/bosun-monitor/repos","events_url":"https://api.github.com/users/bosun-monitor/events{/privacy}","received_events_url":"https://api.github.com/users/bosun-monitor/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bosun-monitor/bosun","description":"Time Series Alerting Framework","fork":false,"url":"https://api.github.com/repos/bosun-monitor/bosun","forks_url":"https://api.github.com/repos/bosun-monitor/bosun/forks","keys_url":"https://api.github.com/repos/bosun-monitor/bosun/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bosun-monitor/bosun/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bosun-monitor/bosun/teams","hooks_url":"https://api.github.com/repos/bosun-monitor/bosun/hooks","issue_events_url":"https://api.github.com/repos/bosun-monitor/bosun/issues/events{/number}","events_url":"https://api.github.com/repos/bosun-monitor/bosun/events","assignees_url":"https://api.github.com/repos/bosun-monitor/bosun/assignees{/user}","branches_url":"https://api.github.com/repos/bosun-monitor/bosun/branches{/branch}","tags_url":"https://api.github.com/repos/bosun-monitor/bosun/tags","blobs_url":"https://api.github.com/repos/bosun-monitor/bosun/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bosun-monitor/bosun/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bosun-monitor/bosun/git/refs{/sha}","trees_url":"https://api.github.com/repos/bosun-monitor/bosun/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bosun-monitor/bosun/statuses/{sha}","languages_url":"https://api.github.com/repos/bosun-monitor/bosun/languages","stargazers_url":"https://api.github.com/repos/bosun-monitor/bosun/stargazers","contributors_url":"https://api.github.com/repos/bosun-monitor/bosun/contributors","subscribers_url":"https://api.github.com/repos/bosun-monitor/bosun/subscribers","subscription_url":"https://api.github.com/repos/bosun-monitor/bosun/subscription","commits_url":"https://api.github.com/repos/bosun-monitor/bosun/commits{/sha}","git_commits_url":"https://api.github.com/repos/bosun-monitor/bosun/git/commits{/sha}","comments_url":"https://api.github.com/repos/bosun-monitor/bosun/comments{/number}","issue_comment_url":"https://api.github.com/repos/bosun-monitor/bosun/issues/comments{/number}","contents_url":"https://api.github.com/repos/bosun-monitor/bosun/contents/{+path}","compare_url":"https://api.github.com/repos/bosun-monitor/bosun/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bosun-monitor/bosun/merges","archive_url":"https://api.github.com/repos/bosun-monitor/bosun/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bosun-monitor/bosun/downloads","issues_url":"https://api.github.com/repos/bosun-monitor/bosun/issues{/number}","pulls_url":"https://api.github.com/repos/bosun-monitor/bosun/pulls{/number}","milestones_url":"https://api.github.com/repos/bosun-monitor/bosun/milestones{/number}","notifications_url":"https://api.github.com/repos/bosun-monitor/bosun/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bosun-monitor/bosun/labels{/name}","releases_url":"https://api.github.com/repos/bosun-monitor/bosun/releases{/id}","created_at":"2013-11-15T00:12:27Z","updated_at":"2015-10-21T02:51:57Z","pushed_at":"2015-10-21T00:08:46Z","git_url":"git://github.com/bosun-monitor/bosun.git","ssh_url":"git@github.com:bosun-monitor/bosun.git","clone_url":"https://github.com/bosun-monitor/bosun.git","svn_url":"https://github.com/bosun-monitor/bosun","homepage":"http://bosun.org","size":54965,"stargazers_count":1424,"watchers_count":1424,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":163,"mirror_url":null,"open_issues_count":219,"forks":163,"open_issues":219,"watchers":1424,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bosun-monitor/bosun/pulls/1407"},"html":{"href":"https://github.com/bosun-monitor/bosun/pull/1407"},"issue":{"href":"https://api.github.com/repos/bosun-monitor/bosun/issues/1407"},"comments":{"href":"https://api.github.com/repos/bosun-monitor/bosun/issues/1407/comments"},"review_comments":{"href":"https://api.github.com/repos/bosun-monitor/bosun/pulls/1407/comments"},"review_comment":{"href":"https://api.github.com/repos/bosun-monitor/bosun/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bosun-monitor/bosun/pulls/1407/commits"},"statuses":{"href":"https://api.github.com/repos/bosun-monitor/bosun/statuses/c276510886f85c9c072df08c86aebcfe7e6c8e75"}}}}