{"action":"created","comment":{"url":"https://api.github.com/repos/bosun-monitor/bosun/pulls/comments/28399191","id":28399191,"diff_hunk":"@@ -1,55 +1,305 @@\n-interface IConfigScope extends ng.IScope {\n-\tcurrent: string;\n-\tresult: string;\n-\terror: string;\n+interface IConfigScope extends IBosunScope {\n+\t// text loading/navigation\n \tconfig_text: string;\n-\teditorOptions: any;\n-\teditor: any;\n-\tcodemirrorLoaded: (editor: any) => void;\n-\tset: () => void;\n-\tline: number;\n+\tselected_alert: string;\n+\titems: { [type: string]: string[]; };\n+\tscrollTo: (type:string,name:string) => void;\n+\taceLoaded: (editor:any) => void;\n+\tvalidate: () => void;\n+\tvalidationResult: string;\n+\tselectAlert: (alert:string) => void;\n+\treparse: () => void;\n+\t\n+\t//rule execution options\n+\tfromDate: string;\n+\ttoDate: string;\n+\tfromTime: string;\n+\ttoTime: string;\n+\tintervals: number;\n+\tduration: number;\n+\temail: string;\n+\ttemplate_group: string;\n+\tsetInterval: () => void;\n+\tsetDuration: () => void;\n+\t\n+\t//rule execution\n+\trunning: boolean;\n+\terror: string;\n+\twarning: string[];\n+\ttest: () => void;\n+\tsets: any;\n+\talert_history: any;\n+\tsubject: string;\n+\tbody: string;\n+\tdata: any;\n+\ttab: string;\n+\tzws: (v: string) => string;\n+\t\n+\tscrollToInterval: (v: string) => void;\n+\tshow: (v: any) => void;\n }\n \n-bosunControllers.controller('ConfigCtrl', ['$scope', '$http', '$location', '$route', function($scope: IConfigScope, $http: ng.IHttpService, $location: ng.ILocationService, $route: ng.route.IRouteService) {\n+\n+\n+bosunControllers.controller('ConfigCtrl', ['$scope', '$http', '$location', '$route', '$timeout','$sce', function($scope: IConfigScope, $http: ng.IHttpService, $location: ng.ILocationService, $route: ng.route.IRouteService, $timeout: ng.ITimeoutService, $sce: ng.ISCEService) {\n \tvar search = $location.search();\n-\tvar current = search.config_text;\n-\tvar line_re = /test:(\\d+)/;\n-\ttry {\n-\t\tcurrent = atob(current);\n+\t$scope.fromDate = search.fromDate || '';\n+\t$scope.fromTime = search.fromTime || '';\n+\t$scope.toDate = search.toDate || '';\n+\t$scope.toTime = search.toTime || '';\n+\t$scope.intervals = +search.intervals || 5;\n+\t$scope.duration = +search.duration || null;\n+\t$scope.config_text = 'Loading config...';\n+\t$scope.selected_alert = search.alert || '';\n+\t$scope.email = search.email || '';\n+\t$scope.template_group = search.template_group || '';\n+\t$scope.items = parseItems();\n+\t$scope.tab = search.tab || 'results';\n+\t\n+\tvar textElem = $(\"#configText\");\n+\t$timeout(()=>{ \n+\t\t\ttextElem.linedtextarea();\n+\t})\n+\t\n+\t\n+\tvar expr = search.expr\n+\t\n+\tfunction buildAlertFromExpr(){\n+\t\tif (!expr) return\n+\t\tvar newAlertName = \"test\";\n+\t\tvar idx = 1;\n+\t\t//find a unique alert name\n+\t\twhile($scope.items[\"alert\"].indexOf(newAlertName) != -1 || $scope.items[\"template\"].indexOf(newAlertName) != -1){\n+\t\t\tnewAlertName = \"test\" + idx;\n+\t\t\tidx++;\n+\t\t}\n+\t\tvar text = '\\n\\ntemplate '+newAlertName+' {\\n' +\n+\t\t\t'\tsubject = {{.Last.Status}}: {{.Alert.Name}} on {{.Group.host}}\\n' +\n+\t\t\t'\tbody = `<p>Name: {{.Alert.Name}}\\n' +\n+\t\t\t'\t<p>Tags:\\n' +\n+\t\t\t'\t<table>\\n' +\n+\t\t\t'\t\t{{range $k, $v := .Group}}\\n' +\n+\t\t\t'\t\t\t<tr><td>{{$k}}</td><td>{{$v}}</td></tr>\\n' +\n+\t\t\t'\t\t{{end}}\\n' +\n+\t\t\t'\t</table>`\\n' +\n+\t\t\t'}\\n\\n';\n+\t\ttext += 'alert '+newAlertName+' {\\n' +\n+\t\t\t'\ttemplate = '+newAlertName+'\\n' +\n+\t\t\t'\tcrit = ' + atob(expr) + '\\n' +\n+\t\t\t'}\\n';\n+\t\t$scope.config_text += text;\n+\t\t$scope.items = parseItems();\n+\t\t$timeout(()=>{ \n+\t\t\t\t//can't scroll editor until after control is updated. Defer it.\n+\t\t\t\t$scope.scrollTo(\"alert\",newAlertName)\n+\t\t})\n \t}\n-\tcatch (e) {\n-\t\tcurrent = '';\n+\t\t\n+\t\n+\tfunction parseItems() : { [type: string]: string[]; }{\n+\t\tvar configText = $scope.config_text;\n+\t\tvar re = /^\\s*(alert|template|notification|lookup|macro)\\s+([\\w\\-\\.\\$]+)\\s*\\{/gm; \n+\t\tvar match;\n+\t\tvar items : { [type: string]: string[]; } = {};\n+\t\titems[\"alert\"] = [];\n+\t\titems[\"template\"] = [];\n+\t\titems[\"lookup\"] = [];\n+\t\titems[\"notification\"] = [];\n+\t\titems[\"macro\"] = [];\n+\t\twhile (match = re.exec(configText)) {\n+        \t\tvar type = match[1];\n+\t\t\tvar name = match[2];\n+\t\t\tvar list = items[type];\n+\t\t\tif (!list){\n+\t\t\t\tlist = [];\n+\t\t\t\titems[type] = list;\n+\t\t\t}\n+\t\t\tlist.push(name)\n+\t\t}\n+\t\treturn items","path":"cmd/bosun/web/static/js/config.ts","position":135,"original_position":135,"commit_id":"f778218f0d38e90eb99ee2e47f5f7e102fc27db5","original_commit_id":"f778218f0d38e90eb99ee2e47f5f7e102fc27db5","user":{"login":"mjibson","id":41181,"avatar_url":"https://avatars.githubusercontent.com/u/41181?v=3","gravatar_id":"","url":"https://api.github.com/users/mjibson","html_url":"https://github.com/mjibson","followers_url":"https://api.github.com/users/mjibson/followers","following_url":"https://api.github.com/users/mjibson/following{/other_user}","gists_url":"https://api.github.com/users/mjibson/gists{/gist_id}","starred_url":"https://api.github.com/users/mjibson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mjibson/subscriptions","organizations_url":"https://api.github.com/users/mjibson/orgs","repos_url":"https://api.github.com/users/mjibson/repos","events_url":"https://api.github.com/users/mjibson/events{/privacy}","received_events_url":"https://api.github.com/users/mjibson/received_events","type":"User","site_admin":false},"body":"semicolon","created_at":"2015-04-15T07:39:36Z","updated_at":"2015-04-15T07:39:36Z","html_url":"https://github.com/bosun-monitor/bosun/pull/868#discussion_r28399191","pull_request_url":"https://api.github.com/repos/bosun-monitor/bosun/pulls/868","_links":{"self":{"href":"https://api.github.com/repos/bosun-monitor/bosun/pulls/comments/28399191"},"html":{"href":"https://github.com/bosun-monitor/bosun/pull/868#discussion_r28399191"},"pull_request":{"href":"https://api.github.com/repos/bosun-monitor/bosun/pulls/868"}}},"pull_request":{"url":"https://api.github.com/repos/bosun-monitor/bosun/pulls/868","id":32557957,"html_url":"https://github.com/bosun-monitor/bosun/pull/868","diff_url":"https://github.com/bosun-monitor/bosun/pull/868.diff","patch_url":"https://github.com/bosun-monitor/bosun/pull/868.patch","issue_url":"https://api.github.com/repos/bosun-monitor/bosun/issues/868","number":868,"state":"open","locked":false,"title":"Config/Rule page unification","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":"New route at `/config2` (temporary) for new combined config/rule page.","created_at":"2015-04-02T22:52:17Z","updated_at":"2015-04-15T07:39:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"54eb005adbcaee9e4383d38264667dd4520df73f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/bosun-monitor/bosun/pulls/868/commits","review_comments_url":"https://api.github.com/repos/bosun-monitor/bosun/pulls/868/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/868/comments","statuses_url":"https://api.github.com/repos/bosun-monitor/bosun/statuses/f778218f0d38e90eb99ee2e47f5f7e102fc27db5","head":{"label":"bosun-monitor:configPage","ref":"configPage","sha":"f778218f0d38e90eb99ee2e47f5f7e102fc27db5","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-04-15T00:53:20Z","pushed_at":"2015-04-14T22:47:06Z","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":32080,"stargazers_count":872,"watchers_count":872,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":98,"mirror_url":null,"open_issues_count":164,"forks":98,"open_issues":164,"watchers":872,"default_branch":"master"}},"base":{"label":"bosun-monitor:master","ref":"master","sha":"0020de2e9cede81f70bdc4849d218f941845069e","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-04-15T00:53:20Z","pushed_at":"2015-04-14T22:47:06Z","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":32080,"stargazers_count":872,"watchers_count":872,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":98,"mirror_url":null,"open_issues_count":164,"forks":98,"open_issues":164,"watchers":872,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bosun-monitor/bosun/pulls/868"},"html":{"href":"https://github.com/bosun-monitor/bosun/pull/868"},"issue":{"href":"https://api.github.com/repos/bosun-monitor/bosun/issues/868"},"comments":{"href":"https://api.github.com/repos/bosun-monitor/bosun/issues/868/comments"},"review_comments":{"href":"https://api.github.com/repos/bosun-monitor/bosun/pulls/868/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/868/commits"},"statuses":{"href":"https://api.github.com/repos/bosun-monitor/bosun/statuses/f778218f0d38e90eb99ee2e47f5f7e102fc27db5"}}}}