1 | <?php |
||
2 | |||
3 | if (! (Auth::user()->hasGlobalAdmin())) { |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
4 | exit('ERROR: You need to be admin'); |
||
5 | } |
||
6 | |||
7 | ?> |
||
8 | |||
9 | <div class="modal fade" id="create-oid-form" tabindex="-1" role="dialog" aria-labelledby="Create" aria-hidden="true"> |
||
10 | <div class="modal-dialog modal-lg"> |
||
11 | <div class="modal-content"> |
||
12 | <div class="modal-header"> |
||
13 | <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> |
||
14 | <h5 class="modal-title" id="Create">Custom OID :: <a target="_blank" href="https://docs.librenms.org/">Docs <i class="fa fa-book fa-1x"></i></a> </h5> |
||
15 | </div> |
||
16 | <div class="modal-body"> |
||
17 | <form method="post" role="form" id="coids" class="form-horizontal coid_form"> |
||
18 | <input type="hidden" name="device_id" id="device_id" value="<?php echo isset($device['device_id']) ? $device['device_id'] : -1; ?>"> |
||
19 | <input type="hidden" name="device_name" id="device_name" value="<?php echo format_hostname($device); ?>"> |
||
20 | <input type="hidden" name="ccustomoid_id" id="ccustomoid_id" value=""> |
||
21 | <input type="hidden" name="type" id="type" value="customoid"> |
||
22 | <input type="hidden" name="action" id="action" value=""> |
||
23 | <div class='form-group' title="A description of the OID"> |
||
24 | <label for='name' class='col-sm-4 col-md-3 control-label'>Name: </label> |
||
25 | <div class='col-sm-8 col-md-9'> |
||
26 | <input type='text' id='name' name='name' class='form-control validation' maxlength='200' required> |
||
27 | </div> |
||
28 | </div> |
||
29 | <div class="form-group" title="SNMP OID"> |
||
30 | <label for='oid' class='col-sm-4 col-md-3 control-label'>OID: </label> |
||
31 | <div class='col-sm-8 col-md-9'> |
||
32 | <input type='text' id='oid' name='oid' class='form-control validation' maxlength='255' required> |
||
33 | </div> |
||
34 | </div> |
||
35 | <div class="form-group" title="SNMP data type"> |
||
36 | <label for='datatype' class='col-sm-4 col-md-3 control-label'>Data Type: </label> |
||
37 | <div class='col-sm-8 col-md-9'> |
||
38 | <select class="form-control" id="datatype" name="datatype"> |
||
39 | <option value="COUNTER">COUNTER</option> |
||
40 | <option value="GAUGE">GAUGE</option> |
||
41 | </select> |
||
42 | </div> |
||
43 | </div> |
||
44 | <div class="form-group" title="Unit of value being polled"> |
||
45 | <label for='unit' class='col-sm-4 col-md-3 control-label'>Unit: </label> |
||
46 | <div class='col-sm-8 col-md-9'> |
||
47 | <input type='text' id='unit' name='unit' class='form-control validation' maxlength='10'> |
||
48 | </div> |
||
49 | </div> |
||
50 | <div class='form-group form-inline'> |
||
51 | <label class='col-sm-4 col-md-3 control-label'>Calculations: </label> |
||
52 | <div class="col-sm-8"> |
||
53 | <label for='divisor' class='col-sm-4 col-md-3 control-label' title="Divide raw SNMP value by">Divisor: </label> |
||
54 | <div class="col-sm-4 col-md-3" title="Divide raw SNMP value by"> |
||
55 | <input type='text' id='divisor' name='divisor' class='form-control' size="4"> |
||
56 | </div> |
||
57 | <label for='multiplier' class='col-sm-4 col-md-3 control-label' title="Multiply raw SNMP value by">Multiplier: </label> |
||
58 | <div class="col-sm-4 col-md-3" title="Multiply raw SNMP value by"> |
||
59 | <input type='text' id='multiplier' name='multiplier' class='form-control' size="4"> |
||
60 | </div> |
||
61 | </div> |
||
62 | </div> |
||
63 | <div class="form-group" title="User function to apply to value"> |
||
64 | <label for='user_func' class='col-sm-4 col-md-3 control-label'>User Function: </label> |
||
65 | <div class='col-sm-8 col-md-9'> |
||
66 | <select class="form-control" id="user_func" name="user_func"> |
||
67 | <option value=""></option> |
||
68 | <option value="celsius_to_fahrenheit">C to F</option> |
||
69 | <option value="fahrenheit_to_celsius">F to C</option> |
||
70 | <option value="uw_to_dbm">uW to dBm</option> |
||
71 | </select> |
||
72 | </div> |
||
73 | </div> |
||
74 | <div class='form-group form-inline'> |
||
75 | <label class='col-sm-4 col-md-3 control-label'>Alert Thresholds: </label> |
||
76 | <div class="col-sm-8"> |
||
77 | <label for='limit' class='col-sm-4 col-md-3 control-label' title="Level to alert above">High: </label> |
||
78 | <div class="col-sm-4 col-md-3" title="Level to alert above"> |
||
79 | <input type='text' id='limit' name='limit' class='form-control' size="4"> |
||
80 | </div> |
||
81 | <label for='limit_low' class='col-sm-4 col-md-3 control-label' title="Level to alert below">Low: </label> |
||
82 | <div class="col-sm-4 col-md-3" title="Level to alert below"> |
||
83 | <input type='text' id='limit_low' name='limit_low' class='form-control' size="4"> |
||
84 | </div> |
||
85 | </div> |
||
86 | </div> |
||
87 | <div class='form-group form-inline'> |
||
88 | <label class='col-sm-4 col-md-3 control-label'>Warning Thresholds: </label> |
||
89 | <div class="col-sm-8"> |
||
90 | <label for='limit_warn' class='col-sm-4 col-md-3 control-label' title="Level to warn above">High: </label> |
||
91 | <div class="col-sm-4 col-md-3" title="Level to warn above"> |
||
92 | <input type='text' id='limit_warn' name='limit_warn' class='form-control' size="4"> |
||
93 | </div> |
||
94 | <label for='limit_low_warn' class='col-sm-4 col-md-3 control-label' title="Level to warn below">Low: </label> |
||
95 | <div class="col-sm-4 col-md-3" title="Level to warn below"> |
||
96 | <input type='text' id='limit_low_warn' name='limit_low_warn' class='form-control' size="4"> |
||
97 | </div> |
||
98 | </div> |
||
99 | </div> |
||
100 | <div class="form-group" title="Alerts for this OID enabled"> |
||
101 | <label for='alerts' class='col-sm-4 col-md-3 control-label'>Alerts Enabled: </label> |
||
102 | <div class='col-sm-4 col-md-3'> |
||
103 | <input type='checkbox' name='alerts' id='alerts'> |
||
104 | </div> |
||
105 | <label for='passed' class='col-sm-4 col-md-3 control-label'>Passed Check: </label> |
||
106 | <div class='col-sm-4 col-md-3'> |
||
107 | <input type='checkbox' name='cpassed' id='cpassed' disabled> |
||
108 | <input type='hidden' name='passed' id='passed' value=""> |
||
109 | </div> |
||
110 | </div> |
||
111 | <div class="form-group"> |
||
112 | <div class="col-sm-12 text-center"> |
||
113 | <button type="button" class="btn btn-success" id="save-oid-button" name="save-oid-button"> |
||
114 | Save OID |
||
115 | </button> |
||
116 | <button type="button" class="btn btn-primary" id="test-oid-button" name="test-oid-button"> |
||
117 | Test OID |
||
118 | </button> |
||
119 | </div> |
||
120 | </div> |
||
121 | <div class='form-group form-inline'> |
||
122 | <div class="col-sm-12"> |
||
123 | <p><small><em>OID will not be polled until a test is successfully complete.</em></small></p> |
||
124 | </div> |
||
125 | </div> |
||
126 | </form> |
||
127 | </div> |
||
128 | </div> |
||
129 | </div> |
||
130 | </div> |
||
131 | |||
132 | <script> |
||
133 | $('#create-oid-form').on('show.bs.modal', function(e) { |
||
134 | var customoid_id = $(e.relatedTarget).data('customoid_id'); |
||
135 | $('#ccustomoid_id').val(customoid_id); |
||
136 | if (customoid_id >= 0) { |
||
137 | $.ajax({ |
||
138 | type: "POST", |
||
139 | url: "ajax_form.php", |
||
140 | data: { type: "parse-customoid", customoid_id: customoid_id }, |
||
141 | dataType: "json", |
||
142 | success: function (data) { |
||
143 | $('#name').val(data.name); |
||
144 | $('#oid').val(data.oid); |
||
145 | $('#datatype').val(data.datatype); |
||
146 | $('#datatype').prop('disabled', true); |
||
147 | $('#unit').val(data.unit); |
||
148 | $('#divisor').val(data.divisor); |
||
149 | $('#multiplier').val(data.multiplier); |
||
150 | $('#user_func').val(data.user_func); |
||
151 | $('#limit').val(data.limit); |
||
152 | $('#limit_warn').val(data.limit_warn); |
||
153 | $('#limit_low').val(data.limit_low); |
||
154 | $('#limit_low_warn').val(data.limit_low_warn); |
||
155 | $('#alerts').prop('checked', data.alerts); |
||
156 | $('#passed').val(data.passed); |
||
157 | $('#cpassed').prop('checked', data.passed); |
||
158 | } |
||
159 | }); |
||
160 | } else { |
||
161 | $('#name').val(''); |
||
162 | $('#oid').val(''); |
||
163 | $('#datatype').val('GAUGE'); |
||
164 | $('#datatype').prop('disabled', false); |
||
165 | $('#unit').val(''); |
||
166 | $('#divisor').val(''); |
||
167 | $('#multiplier').val(''); |
||
168 | $('#user_func').val(''); |
||
169 | $('#limit').val(''); |
||
170 | $('#limit_warn').val(''); |
||
171 | $('#limit_low').val(''); |
||
172 | $('#limit_low_warn').val(''); |
||
173 | $('#alerts').prop('checked', false); |
||
174 | $('#passed').val(''); |
||
175 | $('#cpassed').prop('checked', false); |
||
176 | } |
||
177 | }); |
||
178 | $('#save-oid-button').on('click', function (e) { |
||
179 | e.preventDefault(); |
||
180 | $('#action').val('save'); |
||
181 | $.ajax({ |
||
182 | type: "POST", |
||
183 | url: "ajax_form.php", |
||
184 | data: $('form.coid_form').serializeArray(), |
||
185 | dataType: "json", |
||
186 | success: function (data) { |
||
187 | if (data.status == 'ok') { |
||
188 | toastr.success(data.message); |
||
189 | $('#create-oid-form').modal('hide'); |
||
190 | window.location.reload(); |
||
191 | } else { |
||
192 | toastr.error(data.message); |
||
193 | } |
||
194 | }, |
||
195 | error: function (exception) { |
||
196 | toastr.error('Failed to process OID'); |
||
197 | } |
||
198 | }); |
||
199 | }); |
||
200 | $('#test-oid-button').on('click', function (e) { |
||
201 | e.preventDefault(); |
||
202 | $('#action').val('test'); |
||
203 | $.ajax({ |
||
204 | type: "POST", |
||
205 | url: "ajax_form.php", |
||
206 | data: $('form.coid_form').serializeArray(), |
||
207 | dataType: "json", |
||
208 | success: function (data) { |
||
209 | if (data.status == 'ok') { |
||
210 | toastr.success(data.message); |
||
211 | $("#passed").val('on'); |
||
212 | $("#cpassed").prop("checked", true); |
||
213 | } else { |
||
214 | toastr.error(data.message); |
||
215 | } |
||
216 | }, |
||
217 | error: function (exception) { |
||
218 | toastr.error('Failed to process OID'); |
||
219 | } |
||
220 | }); |
||
221 | }); |
||
222 | $('#oid').on("change", function () { |
||
223 | $("#passed").val(''); |
||
224 | $("#cpassed").prop("checked", false); |
||
225 | }); |
||
226 | </script> |
||
227 |