Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed API usage (includes PR#54, PR#71, PR#74) #78

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion application/clicommands/MibCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ public function purgeAction()

$dbresource=$this->Config()->get('config', 'database');
echo "DB name : $dbresource\n";
$db = IcingaDbConnection::fromResourceName($dbresource)->getConnection();
// $db = IcingaDbConnection::fromResourceName($dbresource)->getConnection();
$db = IcingaDbConnection::fromResourceName($dbresource)->getDbAdapter();

$query = $db->delete(
$Config->getMIBCacheTableName(),
Expand Down
3 changes: 2 additions & 1 deletion application/clicommands/StatusCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public function dbAction()

$dbresource=$this->Config()->get('config', 'database');
printf("DB name : %s\n",$dbresource);
$dataBase = IcingaDbConnection::fromResourceName($dbresource)->getConnection();
// $dataBase = IcingaDbConnection::fromResourceName($dbresource)->getConnection();
$dataBase = IcingaDbConnection::fromResourceName($dbresource)->getDbAdapter();

$query = $dataBase->select()->from($Config->getTrapTableName(),array('COUNT(*)'));
printf("Number of traps : %s\n", $dataBase->fetchOne($query) );
Expand Down
7 changes: 4 additions & 3 deletions application/controllers/HandlerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public function indexAction()
$this->moduleConfig->getHandlerListTitles(),
$this->moduleConfig->getHandlerListDisplayColumns(),
$this->moduleConfig->getHandlerColumns(),
$dbConn->getConnection(),
$dbConn->getDbAdapter(),
// $dbConn->getConnection(),
$this->view,
$this->moduleConfig->urlPath());

Expand Down Expand Up @@ -546,7 +547,7 @@ protected function handlerformAction()
if ($this->apiMode == TRUE)
{
$object=$this->getIdoConn()->getHostGroupById($params['hostid']['val']);
if (count($object) == 0 || $params['host_name']['val'] != $object->__name)
if (empty($object) || $params['host_name']['val'] != $object->__name)
{
$this->_helper->json(array('status'=>"Invalid object group id : Please re enter service"));
return;
Expand Down Expand Up @@ -708,4 +709,4 @@ protected function prepareTabs()
);
}

}
}
7 changes: 5 additions & 2 deletions application/controllers/ReceivedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

namespace Icinga\Module\TrapDirector\Controllers;

use Icinga\Date\DateFormatter;

use Icinga\Web\Url;

use Exception;


use Icinga\Module\Trapdirector\TrapsController;

/**
Expand Down Expand Up @@ -89,7 +92,7 @@ public function trapdetailAction()
// Store result in array (with Titles).
foreach ($queryArray as $key => $val) {
if ($key == 'timestamp') {
$cval=strftime('%c',$trapDetail->$key);
$cval=DateFormatter::formatDateTime($trapDetail->$key);
} else {
$cval=$trapDetail->$key;
}
Expand Down Expand Up @@ -228,4 +231,4 @@ public function deletelinesAction()
$this->_helper->json(array('status'=>'unknown action'));
}

}
}
9 changes: 6 additions & 3 deletions application/controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ private function check_db()

$this->view->ido_db_error=$dberror[0];
$this->view->ido_message='IDO Database : ' . $dberror[1];
$this->view->ido_message .='<br />=&gt; Default to API use. Make sure it is configured and check is returning OK!';
}

/**
Expand Down Expand Up @@ -250,10 +251,10 @@ public function indexAction()
// Test Database
$this->check_db();

//********* Test API
// Test API
$this->check_api();

//*********** Test snmptrapd alive and options
//Test snmptrapd alive and options
list ($this->view->snmptrapdError, $this->view->snmptrapdMessage) = $this->checkSnmpTrapd();

// List DB in $ressources
Expand Down Expand Up @@ -464,7 +465,9 @@ private function checkSnmpTrapd()
exec("$sspath -lun | grep ':162 '",$psOutput);
if (count($psOutput) == 0)
{
return array(1,'Port UDP/162 is not open : is snmptrapd running?');
$extra = "";
if (is_file("/.dockerenv")){ $extra = '<br />=&gt; ignore if Trapdirector is running in a different Docker container'; }
return array(1,'Port UDP/162 is not open : is snmptrapd running?'. $extra);
}
$psOutput=array();
$selinux_state = '';
Expand Down
4 changes: 2 additions & 2 deletions application/controllers/StatusController.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function mibAction()
/** Check for mib file UPLOAD */
if (isset($_FILES['mibfile']))
{
$name=filter_var($_FILES['mibfile']['name'],FILTER_SANITIZE_STRING);
$name=htmlspecialchars($_FILES['mibfile']['name']);
$DirConf=explode(':',$this->Config()->get('config', 'snmptranslate_dirs'));
$destDir=array_shift($DirConf);
if (!is_dir($destDir))
Expand All @@ -147,7 +147,7 @@ public function mibAction()
else
{
$destination = $destDir .'/'.$name; //$this->Module()->getBaseDir() . "/mibs/$name";
$sourceTmpNam=filter_var($_FILES['mibfile']['tmp_name'],FILTER_SANITIZE_STRING);
$sourceTmpNam=htmlspecialchars($_FILES['mibfile']['tmp_name']);
if (move_uploaded_file($sourceTmpNam,$destination)===false)
{
$this->view->uploadStatus="ERROR, file $destination not loaded. Check file and path name or selinux violations";
Expand Down
2 changes: 1 addition & 1 deletion library/Trapdirector/Config/MIBLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public function translateOID($oid)
}
$retArray['description']=null;
/* TODO : put in DB (but maybe only in trap_class).
$query=$db->getConnection()->insert(
$query=$db->getDbAdapter()->insert(
$this->getModuleConfig()->getTrapRuleName(),
$array(
'oid' =>
Expand Down
22 changes: 22 additions & 0 deletions library/Trapdirector/Icinga2API.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,28 @@ public function getServiceById($name)

return $services;
}

/** Get services object by id (host!name)
* does not catch exceptions
* @param $name string service __name (host!name)
* @return array service id
*/
public function getNOKService()
{
$filter = 'service.state != ServiceOK && !(service.acknowledgement || service.downtime_depth || service.host.downtime_depth)';
$services = $this->standardQuery(
'service',
$filter,
array('__name','name','last_check','host_name','state')
);

foreach ( array_keys($services) as $key )
{
$services[$key]->id = $services[$key]->__name;
}

return $services;
}


}
Expand Down
8 changes: 5 additions & 3 deletions library/Trapdirector/Tables/TrapTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Icinga\Data\Selectable;
use Icinga\Data\Paginatable;

use Icinga\Date\DateFormatter;

use Icinga\Web\Request;

use Icinga\Web\Widget;
Expand Down Expand Up @@ -50,7 +52,7 @@ protected function renderDayIfNew($timestamp)
if (in_array(setlocale(LC_ALL, 0), array('en_US.UTF-8', 'C'))) {
$day = date('l, jS F Y', (int) $timestamp);
} else {
$day = strftime('%A, %e. %B, %Y', (int) $timestamp);
$day = DateFormatter::formatDate((int) $timestamp);
}

if ($this->lastDay === $day) {
Expand Down Expand Up @@ -134,7 +136,7 @@ public function getOffset()
{
return $this->offset;
}

#[\ReturnTypeWillChange]
abstract function count();

public function getPaginator()
Expand Down Expand Up @@ -233,4 +235,4 @@ protected function applyFiltersToQuery($query)
return $query;
}

}
}
3 changes: 2 additions & 1 deletion library/Trapdirector/Tables/TrapTableHostList.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Icinga\Module\TrapDirector\Tables;

use Icinga\Date\DateFormatter;

use Icinga\Web\Request;
use Icinga\Web\Url;
Expand Down Expand Up @@ -112,7 +113,7 @@ public function render()
// Check missing value
if (property_exists($row, $rowkey))
{
$val = ($rowkey=='last_sent') ? strftime('%c',$row->$rowkey) : $row->$rowkey;
$val = ($rowkey=='last_sent') ? DateFormatter::formatDateTime($row->$rowkey) : $row->$rowkey;
} else {
$val = '-';
}
Expand Down
5 changes: 3 additions & 2 deletions library/Trapdirector/Tables/TrapTableList.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Icinga\Module\TrapDirector\Tables;

use Icinga\Date\DateFormatter;

use Icinga\Web\Request;
use Icinga\Web\Url;
Expand Down Expand Up @@ -68,7 +69,7 @@ public function render()
// Check missing value
if (property_exists($row, $rowkey))
{
$val = ($rowkey=='timestamp') ? strftime('%T',$row->$rowkey) : $row->$rowkey;
$val = ($rowkey=='timestamp') ? DateFormatter::formatTime($row->$rowkey) : $row->$rowkey;
} else {
$val = '-';
}
Expand Down Expand Up @@ -227,4 +228,4 @@ protected function applyFiltersToQuery($query)
return $query;
}

}
}
7 changes: 4 additions & 3 deletions library/Trapdirector/TrapsActions/UIDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class DBException extends Exception
* @param int $code
* @param Exception $previous
*/
public function __construct(array $retarray, string $message = null, int $code = 0, Exception $previous = null)
public function __construct(array $retarray, string $message = "", int $code = 0, Exception $previous = null)
{
parent::__construct($message,$code,$previous);
$this->returnArray = $retarray;
Expand Down Expand Up @@ -224,7 +224,8 @@ public function getDb()
public function getDbConn()
{
if ($this->getDb() == null) return null;
return $this->getDb()->getConnection();
return $this->getDb()->getDbAdapter();
// return $this->getDb()->getConnection();
}

/**
Expand Down Expand Up @@ -330,4 +331,4 @@ public function testGetIdoDb()
return;
}

}
}
5 changes: 3 additions & 2 deletions library/Trapdirector/TrapsProcess/MibDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ private function update_oid_update()
':syntax' => $this->oidDesc['syntax']==null??'null',
':type_enum' => $this->oidDesc['type_enum']??'null',
':description' => $this->oidDesc['description']??'null',
':id' => $this->dbOidAll[$this->dbOidIndex[$this->oidDesc['oid']]['id']]
':id' => $this->dbOidIndex[$this->oidDesc['oid']]['id']
// ':id' => $this->dbOidAll[$this->dbOidIndex[$this->oidDesc['oid']]['id']]
);

if ($sqlQuery->execute($sqlParam) === false) {
Expand Down Expand Up @@ -191,4 +192,4 @@ private function cache_db_objects($trapId)
}


}
}
Loading