bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/cmd/snmpTester/static/index.html (about) 1 <!doctype html> 2 <html ng-app="snmpApp"> 3 <head> 4 <script src="http://underscorejs.org/underscore.js"></script> 5 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.16/angular.min.js"></script> 6 <script> 7 8 var mibs = JSON.parse(localStorage.getItem("mibs")); 9 var lastMib = localStorage.getItem("lastMib") 10 11 angular.module('snmpApp', []) 12 13 .controller('SnmpController', function($scope, $http, $location) { 14 15 var mib = $location.search().mib 16 if (mib){ 17 var m = JSON.parse(atob(mib)); 18 $scope.mib = m; 19 } 20 21 if(mibs){ 22 $scope.allMibs = mibs 23 if(!$scope.mib && lastMib && mibs[lastMib]){ 24 $scope.mib = _.clone(mibs[lastMib]) 25 } 26 if(lastMib){ 27 $scope.toLoad = lastMib 28 } 29 } 30 31 if(!$scope.mib){ 32 var mib = {Trees:[],Metrics:[]} 33 $scope.mib = mib 34 35 } 36 37 $scope.removeMetric = function(m,a){ 38 var index = a.indexOf(m); 39 if (index > -1) { 40 a.splice(index, 1); 41 } 42 } 43 44 $scope.addMetric = function(a){ 45 a.push({Metric: "", Oid:"", Unit: "", RateType:"", Description: "",FallbackOid: "", Tags:""}) 46 } 47 48 $scope.addTag = function(t){ 49 t.Tags.push({Key: "", Oid: ""}) 50 } 51 52 $scope.addTree = function(){ 53 $scope.mib.Trees.push({BaseOid:"",Tags:[], Metrics:[]}) 54 } 55 56 $scope.removeTag = function(tag,t){ 57 var index = t.Tags.indexOf(tag); 58 if (index > -1) { 59 t.Tags.splice(index, 1); 60 } 61 } 62 63 $scope.removeTree = function(t){ 64 var index = $scope.mib.Trees.indexOf(t); 65 if (index > -1) { 66 $scope.mib.Trees.splice(index, 1); 67 } 68 } 69 70 $scope.test = function(){ 71 $http.post('/test', $scope.mib). 72 success(function(data, status, headers, config) { 73 $scope.results = JSON.stringify(data, null, 2) 74 }). 75 error(function(data, status, headers, config) { 76 $scope.results = data 77 }); 78 } 79 $scope.toml = function(){ 80 $http.post('/toml', $scope.mib). 81 success(function(data, status, headers, config) { 82 $scope.results = data 83 }). 84 error(function(data, status, headers, config) { 85 console.log(data,status,headers, config) 86 $scope.results = data 87 }); 88 } 89 $scope.save = function(){ 90 var n = $scope.mib.Name; 91 if (!n){ 92 alert("name required") 93 return 94 } 95 if (!$scope.allMibs){$scope.allMibs = {};} 96 if (!$scope.allMibs[n] || confirm("Overwrite " + n + "?")){ 97 $scope.allMibs[n] = _.clone($scope.mib); 98 localStorage.setItem("mibs", JSON.stringify($scope.allMibs)) 99 localStorage.setItem("lastMib", n) 100 $scope.toLoad = n; 101 } 102 } 103 $scope.new = function(){ 104 $scope.mib = {Trees:[],Metrics:[]}; 105 $location.search('mib', null); 106 } 107 108 $scope.load = function(){ 109 if (!$scope.allMibs[$scope.toLoad]){ 110 console.log("MIB NOT FOUND", $scope.toLoad) 111 }else{ 112 $scope.mib = _.clone($scope.allMibs[$scope.toLoad]); 113 } 114 } 115 116 $scope.share = function(){ 117 b64 = btoa(JSON.stringify($scope.mib)) 118 $location.search('mib', b64); 119 } 120 121 }); 122 </script> 123 </head> 124 <body ng-controller="SnmpController"> 125 <h3>MIB</h3> 126 Name: <input type='text' ng-model="mib.Name"><br/> 127 Host: <input type='text' ng-model="mib.Host"><br/> 128 Community: <input type='text' ng-model="mib.Community"><br/> 129 Base Oid: <input type='text' ng-model="mib.BaseOid"><br/> 130 <hr/> 131 <h3>Simple Metrics</h3> 132 <ul style='clear:both'> 133 <li ng-repeat="m in mib.Metrics" style='float:left;'><div> 134 Metric: <input type='text' ng-model="m.Metric"> <br/> 135 Oid: <input type='text' ng-model="m.Oid"> <br/> 136 Unit: <input type='text' ng-model="m.Unit"><br/> 137 Rate Type: <input type='text' ng-model="m.RateType"><br/> 138 Description: <input type='text' ng-model="m.Description"><br/> 139 FallbackOid: <input type='text' ng-model="m.FallbackOid"><br/> 140 Tags: <input type='text' ng-model="m.Tags"><br/> 141 <button ng-click="removeMetric(m,mib.Metrics)">Remove</button> 142 </div></li> 143 </ul> 144 <div style='clear:both'></div> 145 <button ng-click="addMetric(mib.Metrics)">Add</button> 146 <hr/> 147 <h3> Trees: </h3> 148 <div ng-repeat="t in mib.Trees"> 149 Base Oid: <input type='text' ng-model="t.BaseOid"><br/> 150 <h4>Tags:</h4> 151 <ul> 152 <li ng-repeat="tag in t.Tags"> 153 Key: <input type='text' ng-model="tag.Key"> 154 Oid: <input type='text' ng-model="tag.Oid"> 155 <button ng-click='removeTag(tag,t)'>remove</button> 156 </li> 157 </ul> 158 <button ng-click="addTag(t)">Add tag</button> 159 <h4>Metrics:</h4> 160 <ul style='clear:both'> 161 <li ng-repeat="m in t.Metrics" style='float:left;'><div> 162 Metric: <input type='text' ng-model="m.Metric"> <br/> 163 Oid: <input type='text' ng-model="m.Oid"> <br/> 164 Unit: <input type='text' ng-model="m.Unit"><br/> 165 Rate Type: <input type='text' ng-model="m.RateType"><br/> 166 Description: <input type='text' ng-model="m.Description"><br/> 167 FallbackOid: <input type='text' ng-model="m.FallbackOid"><br/> 168 Tags: <input type='text' ng-model="m.Tags"><br/> 169 <button ng-click="removeMetric(m,t.Metrics)">Remove</button> 170 </div></li> 171 </ul> 172 <div style='clear:both'></div> 173 <button ng-click="addMetric(t.Metrics)">Add Metric</button><button ng-click="removeTree(t)">Remove Tree</button> 174 </div> 175 <button ng-click="addTree()">Add Tree</button> 176 <hr/> 177 <button ng-click='test()'>TEST!!</button> 178 <button ng-click='toml()'>TOML</button> 179 <button ng-click='share()' style="float:right">share</button> 180 <button ng-click='save()' style="float:right">save</button> 181 <button ng-click='new()' style="float:right">new</button> 182 183 <select style="float:right; margin-right:15px;" ng-show="allMibs" ng-model="toLoad"> 184 <option ng-repeat="(k,v) in allMibs">{{k}}</option> 185 </select> 186 <button ng-click='load()' style="float:right" ng-show="allMibs">load</button> 187 <pre ng-bind="results"> 188 189 </pre> 190 191 </body> 192 </html>