service templates - move to blade -wip

This commit is contained in:
Anthony F McInerney
2020-10-12 14:03:15 +01:00
parent de1ddeb400
commit 124522e72f
13 changed files with 479 additions and 738 deletions
+95
View File
@@ -0,0 +1,95 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use LibreNMS\Interfaces\Models\Keyable;
class Service extends DeviceRelatedModel implements Keyable
{
public $timestamps = false;
protected $primaryKey = 'service_template_id';
protected $fillable = [
'service_template_id',
'device_group_id',
'service_template_ip',
'service_template_type',
'service_template_desc',
'service_template_param',
'service_template_ignore',
'service_template_status',
'service_template_changed',
'service_template_message',
'service_template_disabled',
'service_template_ds',
];
// ---- Helper Functions ----
public function getCompositeKey()
{
return $this->service_template_id . '-' . $this->device_group_id;
}
// ---- Query Scopes ----
/**
* @param Builder $query
* @return Builder
*/
public function scopeIsOk($query)
{
return $query->where([
['service_ignore', '=', 0],
['service_disabled', '=', 0],
['service_status', '=', 0],
]);
}
/**
* @param Builder $query
* @return Builder
*/
public function scopeIsCritical($query)
{
return $query->where([
['service_ignore', '=', 0],
['service_disabled', '=', 0],
['service_status', '=', 2],
]);
}
/**
* @param Builder $query
* @return Builder
*/
public function scopeIsWarning($query)
{
return $query->where([
['service_ignore', '=', 0],
['service_disabled', '=', 0],
['service_status', '=', 1],
]);
}
/**
* @param Builder $query
* @return Builder
*/
public function scopeIsIgnored($query)
{
return $query->where([
['service_ignore', '=', 1],
['service_disabled', '=', 0],
]);
}
/**
* @param Builder $query
* @return Builder
*/
public function scopeIsDisabled($query)
{
return $query->where('service_disabled', 1);
}
}
@@ -1,85 +0,0 @@
<?php
/*
* LibreNMS
*
* Copyright (c) 2016 Aaron Daniels <[email protected]>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
if (Auth::user()->hasGlobalAdmin()) {
?>
<div class="modal fade bs-example-modal-sm" id="confirm-delete" tabindex="-1" role="dialog" aria-labelledby="Delete" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h2 class="modal-title" id="Delete">Delete Service Template</h2>
</div>
<div class='alert alert-warning'>Service Template will be deleted.</div>
<div class='well well-lg'>
<div class="modal-body">
<p>Please confirm that you would like to delete:<?php echo $vars['service_template_name']; ?></p>
</div>
<div class='alert alert-danger'>All Services created by this Template will also be deleted!.</div>
<hr>
<form role="form" class="remove_token_form">
<?php echo csrf_field() ?>
<center><button type="submit" class="btn btn-danger danger" id="service-template-removal"
data-target="service-template-removal">Delete
</button></center>
<input type="hidden" name="service_template_id" id="service_template_id" value="">
<input type="hidden" name="confirm" id="confirm" value="yes">
</form>
</div>
</div>
</div>
</div>
<script>
// on-load
$('#confirm-delete').on('show.bs.modal', function (e) {
service_template_id = $(e.relatedTarget).data('service_template_id');
$("#service_template_id").val(service_template_id);
service_template_name = $(e.relatedTarget).data('service_template_name');
$("#service_template_name").val(service_template_name);
});
// on-submit
$('#service-template-removal').click('', function (e) {
e.preventDefault();
var service_template_id = $("#service_template_id").val();
$.ajax({
type: 'POST',
url: 'ajax_form.php',
data: {type: "delete-service-template", service_template_id: service_template_id},
success: function (result) {
if (result.status == 0) {
// Yay.
$('#message').html('<div class="alert alert-info">' + result.message + '</div>');
$("#row_" + service_template_id).remove();
$("#" + service_template_id).remove();
$("#confirm-delete").modal('hide');
}
else {
// Nay.
$("#message").html('<div class="alert alert-danger">' + result.message + '</div>');
$("#confirm-delete").modal('hide');
}
},
error: function () {
$("#message").html('<div class="alert alert-info">An error occurred deleting this service.</div>');
$("#confirm-delete").modal('hide');
}
});
});
</script>
<?php
}
?>
@@ -1,78 +0,0 @@
<?php
/*
* LibreNMS
*
* Copyright (c) 2016 Aaron Daniels <[email protected]>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
if (Auth::user()->hasGlobalAdmin()) {
?>
<div class="modal fade" id="discover-service-template" tabindex="-1" role="dialog" aria-labelledby="Discover" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h2 class="modal-title" id="Discover">Apply Service Template</h2>
</div>
<div class='alert alert-info'>Service Template will be Applied.</div>
<div class='well well-lg'>
<div class="modal-body">
<p>Please confirm that you would like to discover Devices and apply this Service Template.</p>
</div>
<hr>
<center><button type="submit" class="btn btn-success success" id="confirm-discover-service-template"
data-target="confirm-discover-service-template">Apply
</button></center>
<input type="hidden" name="device_group_id" id="device_group_id" value="">
<input type="hidden" name="service_template_id" id="service_template_id" value="">
<input type="hidden" name="confirm" id="confirm" value="yes">
</div>
</div>
</div>
</div>
<script>
$('#discover-service-template').on('show.bs.modal', function (e) {
device_group_id = $(e.relatedTarget).data('device_group_id');
$("#device_group_id").val(device_group_id);
service_template_id = $(e.relatedTarget).data('service_template_id');
$("#service_template_id").val(service_template_id);
});
$('#confirm-discover-service-template').click('', function (e) {
e.preventDefault();
var device_group_id = $("#device_group_id").val();
var service_template_id = $("#service_template_id").val();
$.ajax({
type: 'POST',
url: 'ajax_form.php',
data: {type: "discover-service-template", device_group_id: device_group_id, service_template_id: service_template_id},
success: function (result) {
if (result.status == 0) {
// Yay.
$('#message').html('<div class="alert alert-info">' + result.message + '</div>');
$("#discover-service-template").modal('hide');
}
else {
// Nay.
$("#message").html('<div class="alert alert-danger">' + result.message + '</div>');
$("#discover-service-template").modal('hide');
}
},
error: function () {
$("#message").html('<div class="alert alert-info">No Services were updated when Applying this Service Template.</div>');
$("#discover-service-template").modal('hide');
}
});
});
</script>
<?php
}
?>
@@ -1,206 +0,0 @@
<?php
/*
* LibreNMS
*
* Copyright (c) 2016 Aaron Daniels <[email protected]>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
if (Auth::user()->hasGlobalAdmin()) {
foreach (dbFetchRows('SELECT * FROM `device_groups` ORDER BY `name`') as $device_group) {
$device_group_id .= "<option value='" . $device_group['id'] . "'>" . $device_group['name'] . '</option>';
}
//foreach (list_available_services() as $current_service) {
// $servicesform .= "<option value='$current_service'>$current_service</option>";
//}
// Build the types list.
$dir = \LibreNMS\Config::get('nagios_plugins');
if (file_exists($dir) && is_dir($dir)) {
$files = scandir($dir);
$dir .= DIRECTORY_SEPARATOR;
foreach ($files as $file) {
if (is_executable($dir . $file) && is_file($dir . $file) && strstr($file, 'check_')) {
[,$check_name] = explode('_', $file, 2);
$stype .= "<option value='$check_name'>$check_name</option>";
}
}
} ?>
<div class="modal fade bs-example-modal-sm" id="create-service-template" tabindex="-1" role="dialog" aria-labelledby="Create" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h2 class="modal-title" id="Create">Edit Services Template</h2>
</div>
<div class='alert alert-info'>Service Template will modified for the specified Device Group.</div>
<div class='well well-lg'>
<div class="modal-body">
<form method="post" role="form" id="service-template" class="form-horizontal service-template-form">
<?php echo csrf_field() ?>
<input type="hidden" name="service_template_id" id="service_template_id" value="">
<input type="hidden" name="type" id="type" value="create-service-template">
<div class="form-group">
<div class="col-sm-12">
<span id="ajax_response">&nbsp;</span>
</div>
</div>
<div class="form-group row">
<label for='name' class='col-sm-3 control-label'>Name: </label>
<div class="col-sm-9">
<input type='text' id='name' name='name' class='form-control input-sm' placeholder=''/>
</div>
<div class='col-sm-9'>
</div>
</div>
<div class="form-group row">
<label for='device_group_id' class='col-sm-3 control-label'>Device Group: </label>
<div class="col-sm-9">
<select id='device_group_id' name='device_group_id' class='form-control input-sm'>
<?php echo $device_group_id?>
</select>
</div>
<div class='col-sm-9'>
</div>
</div>
<div class="form-group row">
<label for='stype' class='col-sm-3 control-label'>Check Type: </label>
<div class="col-sm-9">
<select id='stype' name='stype' placeholder='type' class='form-control input-sm'>
<?php echo $stype?>
</select>
</div>
<div class='col-sm-9'>
</div>
</div>
<div class='form-group row'>
<label for='desc' class='col-sm-3 control-label'>Description: </label>
<div class='col-sm-9'>
<textarea id='desc' name='desc' class='form-control' rows='5'></textarea>
</div>
<div class='col-sm-9'>
</div>
</div>
<div class="form-group row">
<label for='ip' class='col-sm-3 control-label'>Remote Host: </label>
<div class="col-sm-9">
<input type='text' id='ip' name='ip' class='form-control input-sm' placeholder='IP Address or Hostname'/>
</div>
<div class='col-sm-9'>
</div>
</div>
<div class="form-group row">
<label for='param' class='col-sm-3 control-label'>Parameters: </label>
<div class="col-sm-9">
<input type='text' id='param' name='param' class='form-control input-sm' placeholder=''/>
</div>
<div class='col-sm-9'>
</div>
</div>
<div class="form-group row">
<div class="col-sm-12 alert alert-info">
<label class='control-label text-left input-sm'>Parameters may be required and will be different depending on the service check.</label>
</div>
</div>
<div class="form-group row">
<label for='ignore' class='col-sm-3 control-label'>Ignore alert tag: </label>
<div class="col-sm-9">
<input type='checkbox' id='ignore' name='ignore'>
</div>
</div>
<div class="form-group row">
<label for='disabled' class='col-sm-3 control-label'>Disable polling and alerting: </label>
<div class="col-sm-9">
<input type='checkbox' id='disabled' name='disabled'>
</div>
</div>
<hr>
<center><button class="btn btn-primary primary" type="submit" name="service-template-submit" id="service-template-submit" value="save">Save Service Template</button></center>
<div class="clearfix"></div>
</form>
</div>
</div>
</div>
</div>
</div>
<script>
// on-hide
$('#create-service-template').on('hide.bs.modal', function (event) {
$('#device_group_id').val('');
$('#stype').val('');
$('#desc').val('');
$('#ip').val('');
$('#param').val('');
$('#ignore').val('');
$('#disabled').val('');
$('#name').val('');
});
// on-load
$('#create-service-template').on('show.bs.modal', function (e) {
var button = $(e.relatedTarget);
var service_template_id = button.data('service_template_id');
var modal = $(this)
$('#service_template_id').val(service_template_id);
$.ajax({
type: "POST",
url: "ajax_form.php",
data: { type: "parse-service-template", service_template_id: service_template_id },
dataType: "json",
success: function(output) {
$('#device_group_id').val(output['device_group_id']);
$('#stype').val(output['stype']);
$('#desc').val(output['desc']);
$('#ip').val(output['ip']);
$('#param').val(output['param']);
$('#ignore').val(output['ignore']);
$('#disabled').val(output['disabled']);
if ($('#ignore').attr('value') == 1) {
$('#ignore').prop("checked", true);
}
if ($('#disabled').attr('value') == 1) {
$('#disabled').prop("checked", true);
}
$('#name').val(output['name']);
}
});
});
// on-submit
$('#service-template-submit').click('', function(e) {
e.preventDefault();
$.ajax({
type: "POST",
url: "ajax_form.php",
data: $('form.service-template-form').serialize(),
success: function(result){
if (result.status == 0) {
// Yay.
$("#create-service-template").modal('hide');
$('#message').html('<div class="alert alert-info">' + result.message + '</div>');
setTimeout(function() {
location.reload(1);
}, 1500);
}
else {
// Nay.
$("#ajax_response").html('<div class="alert alert-danger">'+result.message+'</div>');
}
},
error: function(){
$("#ajax_response").html('<div class="alert alert-info">An error occurred creating this service template.</div>');
}
});
});
</script>
<?php
}
@@ -1,74 +0,0 @@
<?php
/*
* LibreNMS
*
* Copyright (c) 2016 Aaron Daniels <[email protected]>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
if (Auth::user()->hasGlobalAdmin()) {
?>
<div class="modal fade" id="remove-service-template" tabindex="-1" role="dialog" aria-labelledby="Remove" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h2 class="modal-title" id="Remove">Remove Services</h2>
</div>
<div class='alert alert-warning'>Service Template will be Removed.</div>
<div class='well well-lg'>
<div class="modal-body">
<p>Please confirm that you would like to remove all Services created by this Service Template.</p>
</div>
<hr>
<center><button type="submit" class="btn btn-warning warning" id="confirm-remove-service-template"
data-target="confirm-remove-service-template">Remove
</button></center>
<input type="hidden" name="service_template_id" id="service_template_id" value="">
<input type="hidden" name="confirm" id="confirm" value="yes">
</div>
</div>
</div>
</div>
<script>
$('#remove-service-template').on('show.bs.modal', function (e) {
service_template_id = $(e.relatedTarget).data('service_template_id');
$("#service_template_id").val(service_template_id);
});
$('#confirm-remove-service-template').click('', function (e) {
e.preventDefault();
var service_template_id = $("#service_template_id").val();
$.ajax({
type: 'POST',
url: 'ajax_form.php',
data: {type: "remove-service-template", service_template_id: service_template_id},
success: function (result) {
if (result.status == 0) {
// Yay.
$('#message').html('<div class="alert alert-info">' + result.message + '</div>');
$("#remove-service-template").modal('hide');
}
else {
// Nay.
$("#message").html('<div class="alert alert-danger">' + result.message + '</div>');
$("#remove-service-template").modal('hide');
}
},
error: function () {
$("#message").html('<div class="alert alert-info">No Services were removed for this Service Template.</div>');
$("#remove-service-template").modal('hide');
}
});
});
</script>
<?php
}
?>
@@ -1,42 +0,0 @@
<?php
$no_refresh = true;
if (! Auth::user()->hasGlobalAdmin()) {
include 'includes/html/error-no-perm.inc.php';
} else {
if ($vars['addsrv-template']) {
if (Auth::user()->hasGlobalAdmin()) {
$updated = '1';
$service_template_id = add_service_template($vars['device_group'], $vars['type'], $vars['descr'], $vars['ip'], $vars['params'], $vars['ignore'], $vars['disabled'], $vars['name']);
if ($service_template_id !== null) {
$message .= $message_break . 'Service Template added (' . $service_template_id . ')!';
$message_break .= '<br />';
}
}
}
foreach (list_available_services() as $current_service) {
$servicesform .= "<option value='$current_service'>$current_service</option>";
}
foreach (dbFetchRows('SELECT * FROM `device_groups` ORDER BY `name`') as $device_group) {
$devicegroupsform .= "<option value='" . $device_group['id'] . "'>" . $device_group['name'] . '</option>';
}
if ($updated) {
print_message('Device Settings Saved');
}
$pagetitle[] = 'Add service template';
echo "<div class='row'>
<div class='col-sm-3'>
</div>
<div class='col-sm-6'>";
include_once 'includes/html/print-service-add-template.inc.php';
echo '</div>
</div>';
}//end if
@@ -1,170 +0,0 @@
<?php
/*
* LibreNMS
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*
* @package LibreNMS
* @subpackage webui
* @link http://librenms.org
* @copyright 2017 LibreNMS
* @author LibreNMS Contributors
*/
use LibreNMS\Config;
$pagetitle[] = 'Services Templates';
require_once 'includes/html/modal/new_service_template.inc.php';
require_once 'includes/html/modal/delete_service_template.inc.php';
require_once 'includes/html/modal/discover_service_template.inc.php';
require_once 'includes/html/modal/remove_service_template.inc.php';
?>
<div class="container-fluid">
<div class="row">
<div class="panel panel-default">
<div class="panel-heading">
<span style="font-weight: bold;">Services Templates</span> &#187;
<?php
$menu_options = [
'basic' => 'Basic',
];
if (! $vars['view']) {
$vars['view'] = 'basic';
}
// The menu option - on the left
$sep = '';
foreach ($menu_options as $option => $text) {
if (empty($vars['view'])) {
$vars['view'] = $option;
}
echo $sep;
if ($vars['view'] == $option) {
echo "<span class='pagemenu-selected'>";
}
echo generate_link($text, $vars, [
'view' => $option,
]);
if ($vars['view'] == $option) {
echo '</span>';
}
$sep = ' | ';
}
unset($sep);
// The status option - on the right
echo '<div class="pull-right">';
$sep = '';
unset($sep);
echo '</div>';
echo '</div>';
echo '<div style="margin:10px 10px 0px 10px;" id="message"></div>';
echo '<div class="panel-body">';
$sql_param = [];
$host_par = [];
$perms_sql = null;
if (! Auth::user()->hasGlobalRead()) {
$device_group_ids = Permissions::devicesForUser()->toArray() ?: [0];
$perms_sql .= ' AND `D`.`device_group_id` IN ' . dbGenPlaceholders(count($device_group_ids));
$host_par = $device_group_ids;
}
$host_sql = 'SELECT `D`.`id`,`D`.`name` FROM device_groups AS D, services_template AS S WHERE D.id = S.device_group_id ' . $perms_sql . ' GROUP BY `D`.`name`, `D`.`id` ORDER BY D.`name`';
$shift = 1;
foreach (dbFetchRows($host_sql, $host_par) as $device_group) {
$device_group_id = $device_group['id'];
$device_group_name = $device_group['name'];
$devlink = '<a href="' . generate_url(['page' => 'devices', 'group' => $device_group_id]) . '">' . $device_group_name . '</a>';
if ($shift == 1) {
array_unshift($sql_param, $device_group_id);
$shift = 0;
} else {
$sql_param[0] = $device_group_id;
}
$header = true;
$footer = false;
$service_template_iteration = 0;
$services_template = dbFetchRows("SELECT * FROM `services_template` WHERE `device_group_id` = ? $where ORDER BY service_template_type", $sql_param);
$services_template_count = count($services_template);
foreach ($services_template as $service_template) {
$service_template_iteration++;
if ($service_template_iteration < 2 && $header) {
echo '<div class="panel panel-default">';
echo '<div class="panel-heading"><h3 class="panel-title">' . $devlink . '</h3></div>';
echo '<div class="panel-body">';
echo '<table class="table table-hover table-condensed">';
echo '<thead>';
echo '<th style="width:1%;max-width:1%;"></th>';
echo '<th style="width:10%;max-width: 10%;">Name</th>';
echo '<th style="width:10%;max-width: 10%;">Check Type</th>';
echo '<th style="width:10%;max-width: 15%;">Parameters</th>';
echo '<th style="width:10%;max-width: 15%;">Remote Host</th>';
echo '<th style="width:10%;max-width: 15%;">Description</th>';
echo '<th style="width:10%;max-width: 10%;">Modified</th>';
echo '<th style="width:5%;max-width: 5%;">Ignored</th>';
echo '<th style="width:5%;max-width: 5%;">Disabled</th>';
echo '<th style="width:10%;max-width:10%;"></th>';
echo '</thead>';
}
$header = false;
echo '<tr id="row_' . $service_template['service_template_id'] . '">';
echo '<td><span data-toggle="tooltip" title="' . $title . '" class="alert-status ' . $label . '"></span></td>';
echo '<td>' . nl2br(display($service_template['service_template_name'])) . '</td>';
echo '<td>' . nl2br(display($service_template['service_template_type'])) . '</td>';
echo '<td>' . nl2br(display($service_template['service_template_param'])) . '</td>';
echo '<td>' . nl2br(display($service_template['service_template_ip'])) . '</td>';
echo '<td>' . nl2br(display($service_template['service_template_desc'])) . '</td>';
echo '<td>' . date(Config::get('dateformat.compact'), $service_template['service_template_changed']) . '</td>';
echo '<td>' . nl2br(display($service_template['service_template_ignore'])) . '</td>';
echo '<td>' . nl2br(display($service_template['service_template_disabled'])) . '</td>';
if (Auth::user()->hasGlobalAdmin()) {
echo "<td>
<button type='button' class='btn btn-success btn-sm' aria-label='Apply' data-toggle='modal' data-target='#discover-service-template' data-device_group_id='{$device_group_id}' data-service_template_id='{$service_template['service_template_id']}' name='discover-service-template' title='Apply'><i class='fa fa-plus' aria-hidden='true'></i></button>
<button type='button' class='btn btn-warning btn-sm' aria-label='Remove' data-toggle='modal' data-target='#remove-service-template' data-service_template_id='{$service_template['service_template_id']}' name='remove-service-template' title='Remove'><i class='fa fa-minus' aria-hidden='true'></i></button>
<button type='button' class='btn btn-primary btn-sm' aria-label='Edit' data-toggle='modal' data-target='#create-service-template' data-service_template_id='{$service_template['service_template_id']}' name='edit-service-template' title='Edit'><i class='fa fa-pencil' aria-hidden='true'></i></button>
<button type='button' class='btn btn-danger btn-sm' aria-label='Delete' data-toggle='modal' data-target='#confirm-delete' data-service_template_id='{$service_template['service_template_id']}' data-service_template_name='{$service_template['service_template_name']}' name='delete-service-template' title='Delete'><i class='fa fa-trash' aria-hidden='true'></i></button>
</td>";
}
echo '</tr>';
if ($service_template_iteration >= $services_template_count) {
$footer = true;
}
if ($footer) {
echo '</table>';
echo '</div>';
echo '</div>';
}
}
}
unset($samehost);
?>
</div>
</div>
</div>
</div>
@@ -1,80 +0,0 @@
<?php
echo "
<form id='addsrv-template' name='addsrv-template' method='post' action='' class='form-horizontal' role='form'>
" . csrf_field() . "
<div><h2>Add Service Template</h2></div>
<div class='alert alert-info'>Service Template will created for the specified Device Group.</div>
<div class='well well-lg'>
<div class='form-group'>
<label for='name' class='col-sm-2 control-label'>Name:</label>
<div class='col-sm-5'>
<input name='name' id='name' class='form-control input-sm'>
</div>
<div class='col-sm-5'>
</div>
</div>
<div class='form-group'>
<input type='hidden' name='addsrv-template' value='yes'>
<label for='device_group' class='col-sm-2 control-label'>Device Group:</label>
<div class='col-sm-5'>
<select name='device_group' class='form-control input-sm'>
$devicegroupsform
</select>
</div>
<div class='col-sm-5'>
</div>
</div>
<div class='form-group'>
<label for='type' class='col-sm-2 control-label'>Check Type:</label>
<div class='col-sm-5'>
<select name='type' id='type' class='form-control input-sm'>
$servicesform
</select>
</div>
<div class='col-sm-5'>
</div>
</div>
<div class='form-group'>
<label for='descr' class='col-sm-2 control-label'>Description:</label>
<div class='col-sm-5'>
<textarea name='descr' id='descr' class='form-control input-sm' rows='5'></textarea>
</div>
<div class='col-sm-5'>
</div>
</div>
<div class='form-group'>
<label for='ip' class='col-sm-2 control-label'>Remote Host:</label>
<div class='col-sm-5'>
<input name='ip' id='ip' class='form-control input-sm' placeholder='IP Address or Hostname'>
</div>
<div class='col-sm-5'>
</div>
</div>
<div class='form-group'>
<label for='params' class='col-sm-2 control-label'>Parameters:</label>
<div class='col-sm-5'>
<input name='params' id='params' class='form-control input-sm'>
</div>
</div>
<div class='form-group'>
<div class='col-sm-12 alert alert-info'>
<label class='control-label text-left input-sm'>Parameters may be required and will be different depending on the service check.</label>
</div>
</div>
<div class='form-group'>
<label for='ignore' class='col-sm-2 control-label'>Ignore Alert Tag:</label>
<div class='col-sm-5'>
<input name='ignore' id='ignore' type='checkbox'>
</div>
</div>
<div class='form-group'>
<label for='disabled' class='col-sm-2 control-label'>Disable Polling and Alerting: </label>
<div class='col-sm-5'>
<input name='disabled' id='disabled' type='checkbox'>
</div>
</div>
<hr>
<center><button type='submit' name='Submit' class='btn btn-default input-sm'>Add Service Template</button></center>
</div>
</form>";
+1 -3
View File
@@ -238,7 +238,7 @@
aria-hidden="true"></i> @lang('All Services')</a>
</li>
<li><a href="{{ url('services-templates') }}"><i class="fa fa-cogs fa-fw fa-lg"
aria-hidden="true"></i> @lang('All Services Templates')</a>
aria-hidden="true"></i> @lang('Services Templates')</a>
</li>
@if($service_counts['warning'] || $service_counts['critical'])
<li role="presentation" class="divider"></li>
@@ -259,8 +259,6 @@
<li role="presentation" class="divider"></li>
<li><a href="{{ url('addsrv') }}"><i class="fa fa-plus fa-fw fa-lg"
aria-hidden="true"></i> @lang('Add Service')</a></li>
<li><a href="{{ url('addsrv-template') }}"><i class="fa fa-plus fa-fw fa-lg"
aria-hidden="true"></i> @lang('Add Service Template')</a></li>
@endadmin
</ul>
</li>
@@ -0,0 +1,30 @@
@extends('layouts.librenmsv1')
@section('title', __('Create Device Group'))
@section('content')
<div class="container">
<div class="row">
<form action="{{ route('services-templates.store') }}" method="POST" role="form"
class="form-horizontal services-templates-form col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2 col-sm-12">
<legend>@lang('Create Device Group')</legend>
@csrf
@include('services-templates.form')
<div class="form-group">
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-sm-offset-2">
<button type="submit" class="btn btn-primary">@lang('Save')</button>
<a type="button" class="btn btn-danger"
href="{{ route('services-templates.index') }}">@lang('Cancel')</a>
</div>
</div>
</form>
</div>
</div>
@endsection
@section('javascript')
<script src="{{ asset('js/sql-parser.min.js') }}"></script>
<script src="{{ asset('js/query-builder.standalone.min.js') }}"></script>
@endsection
@@ -0,0 +1,31 @@
@extends('layouts.librenmsv1')
@section('title', __('Edit Device Group'))
@section('content')
<div class="container">
<div class="row">
<form action="{{ route('services-templates.update', $service_template->id) }}" method="POST" role="form"
class="form-horizontal services-templates-form col-md-10 col-md-offset-1 col-sm-12">
<legend>@lang('Edit Device Group'): {{ $service_template->name }}</legend>
{{ method_field('PUT') }}
@csrf
@include('services-templates.form')
<div class="form-group">
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-sm-offset-2">
<button type="submit" class="btn btn-primary">@lang('Save')</button>
<a type="button" class="btn btn-danger"
href="{{ route('services-templates.index') }}">@lang('Cancel')</a>
</div>
</div>
</form>
</div>
</div>
@endsection
@section('javascript')
<script src="{{ asset('js/sql-parser.min.js') }}"></script>
<script src="{{ asset('js/query-builder.standalone.min.js') }}"></script>
@endsection
@@ -0,0 +1,177 @@
<div class="form-group @if($errors->has('name')) has-error @endif">
<label for="name" class="control-label col-sm-3 col-md-2 text-nowrap">@lang('Name')</label>
<div class="col-sm-9 col-md-10">
<input type="text" class="form-control" id="name" name="name" value="{{ old('name', $service_template->name) }}">
<span class="help-block">{{ $errors->first('name') }}</span>
</div>
</div>
<div class="form-group @if($errors->has('device_group_id')) has-error @endif">
<label for="device_group_id" class="control-label col-sm-3 col-md-2 text-nowrap">@lang('Device Group')</label>
<div class="col-sm-9 col-md-10">
<select class="form-control" id=device_group_id" name="device_group_id[]" multiple>
@foreach($device_groups as $device_group)
<option value="{{ $device_group->id }}" selected>{{ $device_group->name() }}</option>
@endforeach
</select>
<span class="help-block">{{ $errors->first('device_group_id') }}</span>
</div>
</div>
<div class="form-group @if($errors->has('type')) has-error @endif">
<label for="type" class="control-label col-sm-3 col-md-2">@lang('Check Type')</label>
<div class="col-sm-9 col-md-10">
<select class="form-control" id=device_group_id" name="device_group_id[]" multiple>
@foreach(list_available_services() as $current_service)
<option value="{{ $current_service }}" selected>{{ $current_service() }}</option>
@endforeach
</select>
<span class="help-block">{{ $errors->first('type') }}</span>
</div>
</div>
<div class="form-group @if($errors->has('desc')) has-error @endif">
<label for="desc" class="control-label col-sm-3 col-md-2 text-nowrap">@lang('Description')</label>
<div class="col-sm-9 col-md-10">
<input type="text" class="form-control" id="desc" name="desc" value="{{ old('desc', $service_template->desc) }}">
<span class="help-block">{{ $errors->first('desc') }}</span>
</div>
</div>
<div class="form-group @if($errors->has('ip')) has-error @endif">
<label for="ip" class="control-label col-sm-3 col-md-2 text-nowrap">@lang('Remote Host')</label>
<div class="col-sm-9 col-md-10">
<input type="text" class="form-control" id="ip" name="ip" value="{{ old('ip', $service_template->ip) }}">
<span class="help-block">{{ $errors->first('ip') }}</span>
</div>
</div>
<div class="form-group @if($errors->has('param')) has-error @endif">
<label for="param" class="control-label col-sm-3 col-md-2 text-nowrap">@lang('Parameters')</label>
<div class="col-sm-9 col-md-10">
<input type="text" class="form-control" id="param" name="param" value="{{ old('param', $service_template->param) }}">
<span class="help-block">{{ $errors->first('param') }}</span>
</div>
</div>
<div class="form-group row">
<div class="col-sm-12 alert alert-info">
<label class='control-label text-left input-sm'>Parameters may be required and will be different depending on the service check.</label>
</div>
</div>
<div class="form-group @if($errors->has('ignore')) has-error @endif">
<label for="ignore" class="control-label col-sm-3 col-md-2 text-nowrap">@lang('Ignore alert tag')</label>
<div class="col-sm-9 col-md-10">
<input type="checkbox" class="form-control" id="ignore" name="ignore" value="{{ old('ignore', $service_template->ignore) }}">
<span class="help-block">{{ $errors->first('ignore') }}</span>
</div>
</div>
<div class="form-group @if($errors->has('ip')) has-error @endif">
<label for="ip" class="control-label col-sm-3 col-md-2 text-nowrap">@lang('Disable polling and alerting')</label>
<div class="col-sm-9 col-md-10">
<input type="checkbox" class="form-control" id="disabled" name="disabled" value="{{ old('disabled', $service_template->disabled) }}">
<span class="help-block">{{ $errors->first('disabled') }}</span>
</div>
</div>
<div id="dynamic-dg-form" class="form-group @if($errors->has('rules')) has-error @endif">
<label for="pattern" class="control-label col-sm-3 col-md-2 text-nowrap">@lang('Define Rules')</label>
<div class="col-sm-9 col-md-10">
<div id="builder"></div>
<span class="help-block">{{ $errors->first('rules') }}</span>
</div>
</div>
<div id="static-dg-form" class="form-group @if($errors->has('devices')) has-error @endif" style="display: none">
<label for="devices" class="control-label col-sm-3 col-md-2 text-nowrap">@lang('Select Devices')</label>
<div class="col-sm-9 col-md-10">
<select class="form-control" id="devices" name="devices[]" multiple>
@foreach($service_template->devices as $device)
<option value="{{ $device->device_id }}" selected>{{ $device->displayName() }}</option>
@endforeach
</select>
<span class="help-block">{{ $errors->first('devices') }}</span>
</div>
</div>
<script>
function change_dg_type(select) {
var type = select.options[select.selectedIndex].value;
document.getElementById("dynamic-dg-form").style.display = (type === 'dynamic' ? 'block' : 'none');
document.getElementById("static-dg-form").style.display = (type === 'dynamic' ? 'none' : 'block');
}
change_dg_type(document.getElementById('type'));
init_select2('#devices', 'device', {multiple: true});
var builder = $('#builder').on('afterApplyRuleFlags.queryBuilder afterCreateRuleFilters.queryBuilder', function () {
$("[name$='_filter']").each(function () {
$(this).select2({
dropdownAutoWidth: true,
width: 'auto'
});
});
}).on('ruleToSQL.queryBuilder.filter', function (e, rule) {
if (rule.operator === 'regexp') {
e.value += ' \'' + rule.value + '\'';
}
}).queryBuilder({
plugins: [
'bt-tooltip-errors'
// 'not-group'
],
filters: {!! $filters !!},
operators: [
'equal', 'not_equal', 'between', 'not_between', 'begins_with', 'not_begins_with', 'contains', 'not_contains', 'ends_with', 'not_ends_with', 'is_empty', 'is_not_empty', 'is_null', 'is_not_null', 'in', 'not_in',
{type: 'less', nb_inputs: 1, multiple: false, apply_to: ['string', 'number', 'datetime']},
{type: 'less_or_equal', nb_inputs: 1, multiple: false, apply_to: ['string', 'number', 'datetime']},
{type: 'greater', nb_inputs: 1, multiple: false, apply_to: ['string', 'number', 'datetime']},
{type: 'greater_or_equal', nb_inputs: 1, multiple: false, apply_to: ['string', 'number', 'datetime']},
{type: 'regex', nb_inputs: 1, multiple: false, apply_to: ['string', 'number']},
{type: 'not_regex', nb_inputs: 1, multiple: false, apply_to: ['string', 'number']}
],
lang: {
operators: {
regexp: 'regex',
not_regex: 'not regex'
}
},
sqlOperators: {
regexp: {op: 'REGEXP'},
not_regexp: {op: 'NOT REGEXP'}
},
sqlRuleOperator: {
'REGEXP': function (v) {
return {val: v, op: 'regexp'};
},
'NOT REGEXP': function (v) {
return {val: v, op: 'not_regexp'};
}
}
});
$('.device-group-form').submit(function (eventObj) {
if ($('#type').val() === 'static') {
return true;
}
if (!builder.queryBuilder('validate')) {
return false;
}
$('<input type="hidden" name="rules" />')
.attr('value', JSON.stringify(builder.queryBuilder('getRules')))
.appendTo(this);
return true;
});
</script>
<script>
var rules = {!! json_encode(old('rules') ? json_decode(old('rules')) : $service_template->rules) !!};
if (rules) {
builder.queryBuilder('setRules', rules);
}
</script>
@@ -0,0 +1,145 @@
@extends('layouts.librenmsv1')
@section('title', __('Services Templates'))
@section('content')
<div class="container-fluid">
<x-panel id="manage-services-templates-panel">
<x-slot name="title">
<i class="fa fa-th fa-fw fa-lg" aria-hidden="true"></i> @lang('Services Templates')
</x-slot>
<div class="row">
<div class="col-md-12">
<a type="button" class="btn btn-success" href="{{ route('services-templates.create') }}">
<i class="fa fa-plus"></i> @lang('New Service Template')
</a>
</div>
</div>
@foreach($device_groups as $device_group)
<x-panel id="manage-services-templates-panel-dg" title="{{ __('Device Group:') }} ({{ $$device_group->name }})">
<div class="table-responsive">
<table id="manage-services-templates-table" class="table table-condensed table-hover">
<thead>
<tr>
<th>@lang('Name')</th>
<th>@lang('Check Type')</th>
<th>@lang('Parameters')</th>
<th>@lang('Remote Host')</th>
<th>@lang('Description')</th>
<th>@lang('Modified')</th>
<th>@lang('Ignored')</th>
<th>@lang('Disabled')</th>
</tr>
</thead>
<tbody>
@foreach($service_templates as $service_template)
<tr id="row_{{ $service_template->service_template_id }}">
<td>{{ $service_template->service_template_name }}</td>
<td>{{ $service_template->service_template_type }}</td>
<td>{{ $service_template->service_template_param }}</td>
<td>{{ $service_template->service_template_ip }}</td>
<td>{{ $service_template->service_template_desc }}</td>
<td>{{ $service_template->service_template_changed }}</td>
<td>{{ $service_template->service_template_ignore }}</td>
<td>{{ $service_template->service_template_disabled }}</td>
<td>
<button type="button" title="@lang('Apply Services for this Service Template')" class="btn btn-success btn-sm" aria-label="@lang('Apply')"
onclick="discover_st(this, '{{ $service_template->service_template_id }}')">
<i
class="fa fa-plus" aria-hidden="true"></i></button>
<button type="button" title="@lang('Remove Services for this Service Template')" class="btn btn-warning btn-sm" aria-label="@lang('Apply')"
onclick="remove_st(this, '{{ $service_template->service_template_id }}')">
<i
class="fa fa-minus" aria-hidden="true"></i></button>
<a type="button" title="@lang('edit Service Template')" class="btn btn-primary btn-sm" aria-label="@lang('Edit')"
href="{{ route('services-templates.edit', $service_template->id) }}">
<i class="fa fa-pencil" aria-hidden="true"></i></a>
<button type="button" class="btn btn-danger btn-sm" title="@lang('delete Service Template')" aria-label="@lang('Delete')"
onclick="delete_st(this, '{{ $service_template->name }}', '{{ route('services-templates.destroy', $service_template->id) }}')">
<i
class="fa fa-trash" aria-hidden="true"></i></button>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</x-panel>
@endforeach
</x-panel>
</div>
@endsection
@section('scripts')
<script>
function discover_st(button, service_template_id) {
if (confirm('@lang('Are you sure you want to create Services for ')' + name + '?')) {
$.ajax({
type: 'POST',
url: 'ajax_form.php',
data: { type: "discover-service-template", service_template_id: service_template_id },
dataType: "json",
success: function(data){
if(data['status'] == 'ok') {
toastr.success(data['message']);
} else {
toastr.error(data['message']);
}
},
error:function(){
toastr.error('No Services were updated when Applying this Service Template');
}
});
}
}
function remove_st(button, service_template_id) {
if (confirm('@lang('Are you sure you want to remove all Services created by ')' + name + '?')) {
$.ajax({
type: 'POST',
url: 'ajax_form.php',
data: { type: "remove-service-template", service_template_id: service_template_id },
dataType: "json",
success: function(data){
if(data['status'] == 'ok') {
toastr.success(data['message']);
} else {
toastr.error(data['message']);
}
},
error:function(){
toastr.error('No Services were removed for this Service Template');
}
});
}
}
function delete_st(button, service_template_id) {
if (confirm('@lang('Are you sure you want to delete AND remove all Services created by ')' + name + '?')) {
$.ajax({
type: 'POST',
url: 'ajax_form.php',
data: { type: "delete-service-template", service_template_id: service_template_id },
dataType: "json",
success: function(data){
if(data['status'] == 'ok') {
toastr.success(data['message']);
} else {
toastr.error(data['message']);
}
},
error:function(){
toastr.error('An error occurred deleting this Service Template');
}
});
}
}
</script>
@endsection
@section('css')
<style>
.table-responsive {
padding-top: 16px
}
</style>
@endsection