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

add SNMP Profiles #173

Open
wants to merge 1 commit 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
63 changes: 63 additions & 0 deletions wwwroot/inc/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -6060,4 +6060,67 @@ function releaseDBMutex ($name)
return $row === '1';
}

function getSNMPProfile ($id = NULL)
{
$query = 'SELECT id, name, version as ver, community, sec_name,
sec_level, auth_protocol, auth_passphrase,
priv_protocol, priv_passphrase,
contextname, contextengineid,
(SELECT count(SNMPProfileMapping.profile_id) FROM SNMPProfileMapping WHERE SNMPProfileMapping.profile_id = SNMPProfile.id) as refs
FROM SNMPProfile';

$params = array();
if ($id !== NULL)
{
$query .= ' WHERE id = ?';
$params[] = $id;
}

$result = usePreparedSelectBlade ($query, $params);

if ($id !== NULL)
return $result->fetch (PDO::FETCH_ASSOC);
else
return reindexById ($result->fetchAll (PDO::FETCH_ASSOC));
}

function getObjectSNMPProfile ($object_id)
{
$result = usePreparedSelectBlade
(
'SELECT profile_id as id, host
FROM SNMPProfileMapping
WHERE object_id = ?',
array ($object_id)
);
$ret = $result->fetch (PDO::FETCH_ASSOC);

if ($ret === FALSE)
return FALSE;

$profile = getSNMPProfile ($ret['id']);

if (! $profile)
return FALSE;

return array_merge ($ret, $profile);
}

function setObjectSNMPProfile ($object_id, $profile_id, $host = NULL)
{
if ($profile_id == 0)
{
usePreparedDeleteBlade ('SNMPProfileMapping', array ('object_id' => $object_id));
return -1;
}
else
return usePreparedExecuteBlade
(
'INSERT INTO SNMPProfileMapping(object_id, profile_id, host)
VALUES(?, ?, ?)
ON DUPLICATE KEY UPDATE profile_id = ?, host = ?',
array ($object_id, $profile_id, $host, $profile_id, $host)
);
}

?>
24 changes: 24 additions & 0 deletions wwwroot/inc/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,30 @@ function get_pseudo_file ($name)
CONSTRAINT `VSEnabledPorts-FK-vs_id-proto-vport` FOREIGN KEY (`vs_id`, `proto`, `vport`) REFERENCES `VSPorts` (`vs_id`, `proto`, `vport`) ON DELETE CASCADE
) ENGINE=InnoDB";

$query[] = "CREATE TABLE `SNMPProfile` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` char(255) DEFAULT NULL,
`version` tinyint DEFAULT NULL,
`community` char(255) DEFAULT NULL,
`sec_name` char(255) DEFAULT NULL,
`sec_level` char(12) DEFAULT NULL,
`auth_protocol` char(3) DEFAULT NULL,
`auth_passphrase` char(255) DEFAULT NULL,
`priv_protocol` char(3) DEFAULT NULL,
`priv_passphrase` char(255) DEFAULT NULL,
`contextname` char(255) DEFAULT NULL,
`contextengineid` char(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB";

$query[] = "CREATE TABLE `SNMPProfileMapping` (
`object_id` int(10) unsigned not NULL,
`profile_id` int(10) unsigned not NULL,
`host` char(255) DEFAULT NULL,
PRIMARY KEY (`object_id`),
CONSTRAINT `SNMPProfileMapping_object_id` FOREIGN KEY (`object_id`) REFERENCES `Object` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB";

$query[] = "
CREATE TRIGGER `EntityLink-before-insert` BEFORE INSERT ON `EntityLink` FOR EACH ROW
EntityLinkTrigger:BEGIN
Expand Down
51 changes: 51 additions & 0 deletions wwwroot/inc/interface-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -1165,4 +1165,55 @@ function printNewItemTR()
echo '</table>';
}

function renderSNMPProfiles ()
{
startPortlet ("SNMP Profiles");

$cols = array (
array ('row_key' => 'id', 'th_text' => 'Id'),
array ('row_key' => 'name', 'th_text' => 'Name'),
array ('row_key' => 'ver', 'th_text' => 'Version'),
array ('row_key' => 'community', 'th_text' => 'Community'),
array ('row_key' => 'sec_name', 'th_text' => 'Security Name'),
array ('row_key' => 'sec_level', 'th_text' => 'Security Level'),
array ('row_key' => 'auth_protocol', 'th_text' => 'Auth Protocol'),
array ('row_key' => 'priv_protocol', 'th_text' => 'Priv Protocol')
);

renderTableViewer ($cols, getSNMPProfile ());

finishPortlet ();
}

function renderSNMPProfilesEditor ()
{
startPortlet ("SNMP Profiles");

addSNMPProfileFormJS (TRUE);

echo '<table cellspacing=0 cellpadding=5 align=center class="widetable zebra">';
echo '<thead><tr>
<th></th>
<th>Id</th>
<th>Name</th>
<th>Version</th>
<th>Community/<br>Security Name</th>
<th>Security Level</th>
<th>Auth<br>Protocol</th>
<th>Auth<br>Passphrase</th>
<th>Priv<br>Protocol</th>
<th>Priv<br>Passphrase</th>
</tr></thead>';

echo '<tbody>';
printSNMPProfileFormFields (array ('id' => 'new'), FALSE, FALSE);
foreach (getSNMPProfile () as $profile)
{
printSNMPProfileFormFields ($profile, FALSE, FALSE);
}
echo '</tbody></table>';

finishPortlet ();
}

?>
Loading