Skip to content

Commit

Permalink
Added boot time for minions for issue #23
Browse files Browse the repository at this point in the history
  • Loading branch information
neilmunday committed Apr 25, 2019
1 parent 41e9f3a commit 938200b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 17 deletions.
1 change: 1 addition & 0 deletions database.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ CREATE TABLE `interface` (
DROP TABLE IF EXISTS `minion`;
CREATE TABLE `minion` (
`server_id` int(11) unsigned NOT NULL,
`boot_time` int(11) unsigned DEFAULT NULL,
`last_audit` int(11) unsigned DEFAULT NULL,
`last_seen` int(11) unsigned DEFAULT NULL,
`id` varchar(255) NOT NULL,
Expand Down
2 changes: 1 addition & 1 deletion html/json/minions.json.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
require_once($root . "/common/common.php");

$data = array();
$sth = dbQuery("SELECT `server_id`, `id`, `host`, `fqdn`, `biosversion`, `biosreleasedate`, `cpu_model`, `kernel`, `kernelrelease`, `os`, `osrelease`, `saltversion`, `last_seen`, `last_audit`, `last_seen`, `package_total`, `selinux_enforced`, (SELECT COUNT(*) FROM `minion_user` WHERE `minion_user`.`server_id` = `minion`.`server_id`) AS `users` FROM `minion`;");
$sth = dbQuery("SELECT `server_id`, `id`, `host`, `fqdn`, `biosversion`, `biosreleasedate`, `cpu_model`, `kernel`, `kernelrelease`, `os`, `osrelease`, `saltversion`, `last_seen`, `last_audit`, `boot_time`, `package_total`, `selinux_enforced`, (SELECT COUNT(*) FROM `minion_user` WHERE `minion_user`.`server_id` = `minion`.`server_id`) AS `users` FROM `minion`;");

$data['data'] = array();
while($row = $sth->fetch()) {
Expand Down
39 changes: 23 additions & 16 deletions html/minions.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
along with Salt Minion Inventory. If not, see <http://www.gnu.org/licenses/>.
*/

define('DATE_FORMAT', 'Y-m-d H:i:s');

$root = dirname(__FILE__);
require_once($root . "/common/common.php");

Expand Down Expand Up @@ -70,8 +72,10 @@ function details($id) {
}

$jsonPackages = mkPath("/json/packages.json.php?id=" . $id);
$lastSeen = date('Y-m-d H:i:s', $row["last_seen"]);
$lastAudit = date('Y-m-d H:i:s', $row["last_audit"]);

$lastSeen = date(DATE_FORMAT, $row["last_seen"]);
$lastAudit = date(DATE_FORMAT, $row["last_audit"]);
$booted = date(DATE_FORMAT, $row["boot_time"]);

$active = filter_input(INPUT_GET, 'tab', FILTER_SANITIZE_STRING);

Expand Down Expand Up @@ -120,6 +124,7 @@ function details($id) {
printf("%s\t\t<tr><td>Memory:</td><td>%s MB</td></tr>\n", $prefix, $row["mem_total"]);
printf("%s\t\t<tr><td>BIOS:</td><td>%s (%s)</td></tr>\n", $prefix, $row["biosversion"], $row["biosreleasedate"]);
printf("%s\t\t<tr><td>Serial:</td><td>%s</td></tr>\n", $prefix, $row["server_serial"]);
printf("%s\t\t<tr><td nowrap>Booted:</td><td>%s</td></tr>\n", $prefix, $booted);
printf("%s\t\t<tr><td nowrap>Last Seen:</td><td>%s</td></tr>\n", $prefix, $lastSeen);
printf("%s\t</table>\n", $prefix);
break;
Expand Down Expand Up @@ -265,28 +270,29 @@ className : 'select-checkbox',
return "";
}
},
{data : "server_id", visible : false},
{
data : "fqdn",
render: function(data, type, row, meta) {
return "<a href=\"minions.php?id=" + row["server_id"] + "\">" + data + "</a>";
}
},
{data : "os"},
{ data : "server_id", visible : false},
{
data : "fqdn",
render: function(data, type, row, meta) {
return "<a href=\"minions.php?id=" + row["server_id"] + "\">" + data + "</a>";
}
},
{data : "os"},
{data : "osrelease"},
{data : "kernelrelease" },
{
data: "package_total",
render: function(data, type, row, meta) {
if (data == 0) {
return 0;
}
return "<a href=\"minions.php?id=" + row["server_id"] + "&amp;tab=Packages\">" + data + "</a>";
data: "package_total",
render: function(data, type, row, meta) {
if (data == 0) {
return 0;
}
return "<a href=\"minions.php?id=" + row["server_id"] + "&amp;tab=Packages\">" + data + "</a>";
}
},
{ data: "users" },
{ data: "saltversion" },
{ data: "selinux_enforced" },
{ data: "boot_time", render: $.fn.dataTable.render.moment('X', 'YYYY-MM-DD HH:mm') },
{ data: "last_seen", render: $.fn.dataTable.render.moment('X', 'YYYY-MM-DD HH:mm') },
{ data: "last_audit", render: $.fn.dataTable.render.moment('X', 'YYYY-MM-DD HH:mm') }
],
Expand Down Expand Up @@ -356,6 +362,7 @@ className : 'select-checkbox',
<th>Users</th>
<th>Salt Version</th>
<th>Selinux</th>
<th>Booted</th>
<th>Last Seen</th>
<th>Last Audit</th>
</tr>
Expand Down
5 changes: 5 additions & 0 deletions runners/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def audit(ts, properties, propertiesChanged):
SET
`os` = \"%s\",
`osrelease` = \"%s\",
`boot_time` = %d,
`last_audit` = %d,
`id` = \"%s\",
`server_model_id` = %d,
Expand All @@ -173,6 +174,7 @@ def audit(ts, properties, propertiesChanged):
""" % (
properties["os"],
properties["osrelease"],
properties["boot_time"],
ts,
properties["id"],
modelId,
Expand Down Expand Up @@ -200,6 +202,7 @@ def audit(ts, properties, propertiesChanged):
query = """
INSERT into `minion` (
`server_id`,
`boot_time`,
`last_audit`,
`last_seen`,
`id`,
Expand All @@ -226,6 +229,7 @@ def audit(ts, properties, propertiesChanged):
%d,
%d,
%d,
%d,
"%s",
"%s",
"%s",
Expand All @@ -246,6 +250,7 @@ def audit(ts, properties, propertiesChanged):
);
""" % (
properties["server_id"],
properties["boot_time"],
ts,
ts,
properties["id"],
Expand Down
2 changes: 2 additions & 0 deletions srv/salt/_modules/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ def audit(force=False):
if u['user'] not in properties['users']:
properties['users'].append(u['user'])

properties['boot_time'] = __salt__['status.uptime']()['since_t']

lsblkRe = re.compile('([A-Z]+)="(.*?)"')
for line in __salt__['cmd.run']('lsblk -d -o name,serial,vendor,size,type -P -n').split("\n"):
matches = lsblkRe.findall(line)
Expand Down

0 comments on commit 938200b

Please sign in to comment.