Skip to content

Commit

Permalink
issue #43 : added comment
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickpr committed Sep 5, 2020
1 parent f89bd2c commit 1d8afef
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 14 deletions.
9 changes: 7 additions & 2 deletions application/controllers/HandlerController.php
Expand Up @@ -36,11 +36,11 @@ public function indexAction()
$this->view,
$this->moduleConfig->urlPath());

$this->view->handlerTable->setMaxPerPage($this->getModuleConfig()->itemListDisplay());

$getVars = $this->getRequest()->getParams();
$this->view->handlerTable->getParams($getVars);

//$this->view->handlerTable->setFilter('127.0.0.1',array('ip4'));

$this->view->handlerTable->setMibloader($this->getMIB());


Expand Down Expand Up @@ -376,6 +376,9 @@ public function addAction()
$this->view->modified=gmdate("Y-m-d\TH:i:s\Z",$ruleDetail->modified);
$this->view->modifier=$ruleDetail->modifier;

$this->view->comment = $ruleDetail->comment;
$this->view->category = $ruleDetail->category;

// Warning message if host/service don't exists anymore
$this->view->warning_message='';
if ($this->view->hostname != null)
Expand Down Expand Up @@ -432,6 +435,8 @@ protected function handlerformAction()
'host_group_name'=> array('post' => null, 'val' => null, 'db'=>true),
'serviceid' => array('post' => 'serviceid', 'db'=>false),
'service_name' => array('post' => 'serviceName', 'db'=>true),
'comment' => array('post' => 'comment', 'val' => '', 'db'=>true),
'rule_type' => array('post' => 'category', 'val' => 0, 'db'=>true),
'trap_oid' => array('post' => 'oid', 'db'=>true),
'revert_ok' => array('post' => 'revertOK', 'val' => 0, 'db'=>true),
'display' => array('post' => 'display', 'val' => '', 'db'=>true),
Expand Down
51 changes: 43 additions & 8 deletions application/views/scripts/handler/add.phtml
Expand Up @@ -26,7 +26,9 @@ use Icinga\Web\Url;
?>
<input type="hidden" name="hostid" id="id_Hidden_hostgroup"
value="<?= $this->hostgroupid ?>">
<fieldset id="fieldset-source_definition" class=""><legend>Trap source</legend>
<fieldset id="fieldset-source_definition" class=""><legend>Trap source and handler information</legend>
<table> <tr>
<td>
<input type="checkbox" id="id_host_or_hostgroup"
onChange="toggle_host_hostgroup()"
<?php if ($this->selectGroup) { echo 'checked'; } ?>>
Expand All @@ -41,7 +43,7 @@ use Icinga\Web\Url;
<label for="id_hostgroupfilter" class="control-label optional">Host group</label>
</span>
</div>
<input type="text" name="hostgroup" id="id_hostgroupfilter" placeholder="Enter partial name" list="hostgroups_list"
<input type="text" name="hostgroup" id="id_hostgroupfilter" placeholder="Enter partial name" list="hostgroups_list" size=30
oninput="hostGroupFilterGet()"
value="<?= $this->hostgroupname ?>" > <!-- onblur="serviceGet()" onkeypress="hostFilterGet()-->
<datalist id="hostgroups_list">
Expand Down Expand Up @@ -70,7 +72,7 @@ use Icinga\Web\Url;
<label for="id_hostfilter" class="control-label optional">Host name</label>
</span>
</div>
<input type="text" name="hostfilter" id="id_hostfilter" placeholder="Enter partial name" list="hosts_list"
<input type="text" name="hostfilter" id="id_hostfilter" placeholder="Enter partial name" list="hosts_list" size=30
oninput="hostFilterGet()"
value="<?= $this->hostname ?>" > <!-- onblur="serviceGet()" onkeypress="hostFilterGet()-->
<datalist id="hosts_list">
Expand All @@ -96,6 +98,30 @@ use Icinga\Web\Url;
</select>
</div>
</div>
</td>
<td style="padding-left: 150px;">
<div class="control-group">
<div class="control-label-group">
<span id="id_comment_span_label">
<label for="id_comment" class="control-label optional">Handler comment</label>
</span>
</div>
<input type="text" name="coment" id="id_comment" placeholder="Enter trap handler comment here" list="hosts_list" size=60
value="<?= $this->comment ?>" >
</div>
<div class="control-group">
<div class="control-label-group">
<span>
<label for="id_handler_category" class="control-label optional">Handler category</label>
</span>
</div>
<select name="service" id="id_handler_category" >
<option value="0" selected>Not categorized</option>
</select>
</div>
</td>
</tr>
</table>
</fieldset>

<fieldset id="fieldset-objects_definition" class=""><legend>Trap definition</legend>
Expand Down Expand Up @@ -147,7 +173,7 @@ use Icinga\Web\Url;
<label for="id_mainoid" class="control-label optional">Trap OID</label>
</span>
</div>
<input type="text" name="mainoid" id="id_mainoid" placeholder="Enter oid"
<input type="text" name="mainoid" id="id_mainoid" placeholder="Enter oid" size=40
value="<?= $this->mainoid ?>" >
<span id="id_mainoid_trapname"> MIB::name </span>
<button type="button" disabled id="id_mainoid_add_objects" onclick="onclickAddObjects()">
Expand Down Expand Up @@ -303,12 +329,12 @@ count_id=1;

function displayWarning(message)
{
$("#footer > #notifications").html('<li class="error fading-out">'+message+'</li>');
$("#footer > #notifications").html('<li class="error">'+message+'</li>');
//alert(message);
}
function displayOK(message)
{
$("#footer > #notifications").html('<li class="success fading-out">'+message+'</li>');
$("#footer > #notifications").html('<li class="success">'+message+'</li>');
}

function setToUpdate()
Expand Down Expand Up @@ -359,6 +385,7 @@ function deleteMain()

function submitMain(clone)
{

// Check everything
// Hostname/hostgroup
hostgroupSel=$("#id_host_or_hostgroup").is(":checked");
Expand Down Expand Up @@ -389,7 +416,7 @@ function submitMain(clone)
{
getOID = '.'+getOID;
}

// Get revert time
var timeRegexp = /^[\d]*$/;
var revertOK=$("#id_revertOK").val()
Expand All @@ -406,6 +433,11 @@ function submitMain(clone)
newDisplay=newDisplay.replace(objRegexp,'_OID('+ objectsList[i][1] +')');

}

// Get comment and category
comment = $("#id_comment").val();
category = $("#id_handler_category").val();

if (clone == 1)
{
actionFormVal='clone';
Expand All @@ -414,6 +446,7 @@ function submitMain(clone)
{
actionFormVal='save';
}

// Do ajax call
$.ajax({
url: form_submit,
Expand All @@ -428,6 +461,8 @@ function submitMain(clone)
"hostname" : hostname,
"serviceid" : serviceid,
"serviceName" : servicename,
"comment" : comment,
"category" : category,
"oid" : getOID,
"revertOK" : revertOK,
"display" : newDisplay,
Expand Down Expand Up @@ -456,7 +491,7 @@ function submitMain(clone)
displayWarning ("error" + data);
}
});

}

function toggle_host_hostgroup()
Expand Down
6 changes: 5 additions & 1 deletion library/Trapdirector/Config/TrapModuleConfig.php
Expand Up @@ -155,6 +155,8 @@ public function getHandlerListDisplayColumns()
'source_ip' => "CASE WHEN r.ip4 IS NULL THEN r.ip6 ELSE r.ip4 END",
'trap_oid' => 'r.trap_oid',
'rule' => 'r.rule',
'comment' => 'r.comment',
'category' => 'r.rule_type',
'action_match' => 'r.action_match',
'action_nomatch'=> 'r.action_nomatch',
'service_name' => 'r.service_name',
Expand Down Expand Up @@ -209,7 +211,9 @@ public function ruleDetailQuery()
'revert_ok' => 'r.revert_ok',
'display' => 'r.display',
'modified' => 'UNIX_TIMESTAMP(r.modified)',
'modifier' => 'r.modifier'
'modifier' => 'r.modifier',
'comment' => 'r.comment',
'category' => 'r.rule_type'
);
}

Expand Down
10 changes: 7 additions & 3 deletions library/Trapdirector/Tables/HandlerTable.php
Expand Up @@ -98,15 +98,19 @@ public function renderLine($row)
$val = '-';
}
if ($firstCol === true) { // Put link in first column for trap detail.
$html .= '<td>'
$html .= '<td class="traphover">'
. $this->view->qlink(
$this->view->escape($val),
Url::fromPath(
$this->urlPath . '/handler/add',
array('ruleid' => $row->id)
)
)
. '</td>';
);
if ($row->comment != '')
{
$html.= '<span class="tohover">'. $row->comment .'</span></td>';
}
$html.= '</td>';
} else {
$html .= '<td>' . $this->view->escape($val) . '</td>';
}
Expand Down

0 comments on commit 1d8afef

Please sign in to comment.