Skip to content

Commit b60e7fa

Browse files
committed
First commit, plugin's initial revision
1 parent 06d3cae commit b60e7fa

File tree

6 files changed

+225
-0
lines changed

6 files changed

+225
-0
lines changed

APACHE/Map.pm

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
###############################################################################
2+
## OCSINVENTORY-NG
3+
## Copyleft Guillaume PROTET 2013
4+
## Web : http://www.ocsinventory-ng.org
5+
##
6+
## This code is open source and may be copied and modified as long as the source
7+
## code is always made freely available.
8+
## Please refer to the General Public Licence http://www.gnu.org/ or Licence.txt
9+
################################################################################
10+
11+
package Apache::Ocsinventory::Plugins::Uptime::Map;
12+
13+
use strict;
14+
15+
use Apache::Ocsinventory::Map;
16+
#Plugin UPTIME
17+
$DATA_MAP{uptime} = {
18+
mask => 0,
19+
multi => 1,
20+
auto => 1,
21+
delOnReplace => 1,
22+
sortBy => 'TIME',
23+
writeDiff => 0,
24+
cache => 0,
25+
fields => {
26+
TIME => {},
27+
}
28+
};
29+
1;

APACHE/uptime.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PerlModule Apache::Ocsinventory::Plugins::Uptime::Map;

agent/Unix/uptime.pm

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
###############################################################################
2+
## OCSINVENTORY-NG
3+
## Copyleft Guillaume PROTET 2010
4+
## Web : http://www.ocsinventory-ng.org
5+
##
6+
## This code is open source and may be copied and modified as long as the source
7+
## code is always made freely available.
8+
## Please refer to the General Public Licence http://www.gnu.org/ or Licence.txt
9+
################################################################################
10+
11+
package Ocsinventory::Agent::Modules::Uptime;
12+
13+
sub new {
14+
15+
my $name="uptime"; # Name of the module
16+
17+
my (undef,$context) = @_;
18+
my $self = {};
19+
20+
#Create a special logger for the module
21+
$self->{logger} = new Ocsinventory::Logger ({
22+
config => $context->{config}
23+
});
24+
25+
$self->{logger}->{header}="[$name]";
26+
27+
$self->{context}=$context;
28+
29+
$self->{structure}= {
30+
name => $name,
31+
start_handler => undef, #or undef if don't use this hook
32+
prolog_writer => undef, #or undef if don't use this hook
33+
prolog_reader => undef, #or undef if don't use this hook
34+
inventory_handler => $name."_inventory_handler", #or undef if don't use this hook
35+
end_handler => undef #or undef if don't use this hook
36+
};
37+
38+
bless $self;
39+
}
40+
41+
######### Hook methods ############
42+
43+
sub uptime_inventory_handler {
44+
45+
my $self = shift;
46+
my $logger = $self->{logger};
47+
48+
my $common = $self->{context}->{common};
49+
50+
#I add the treatments for my new killer feature
51+
$logger->debug("Yeah you are in uptime_inventory_handler :)");
52+
53+
my $luptime = `cat /proc/uptime | awk '{print $1}'`;
54+
my $uptime = undef;
55+
56+
# These help us calculate the minutes and hours
57+
my $min=60;
58+
my $hour = $min*60;
59+
my $day = $hour*24;
60+
61+
my $minutes = 0;
62+
my $hours = 0;
63+
my $days = 0;
64+
65+
# Make the uptime number integer
66+
my $seconds = int($luptime);
67+
68+
while ($seconds >= $min) {
69+
while ($seconds >= $hour) {
70+
while ($seconds >= $day) {
71+
$seconds -= $day;
72+
++$days;
73+
}
74+
$seconds -= $hour;
75+
++$hours;
76+
}
77+
$seconds -= $min;
78+
++$minutes
79+
}
80+
if($seconds < 10) { $seconds = "0$seconds"; }
81+
if($minutes < 10) { $minutes = "0$minutes"; }
82+
if($hours < 10) {$hours = "0$hours"; }
83+
if($days < 10) {$days = "0$days"; }
84+
85+
#print "$days:$hours:$minutes:$seconds";
86+
87+
$uptime = "$days days $hours hours $minutes minutes";
88+
89+
push @{$common->{xmltags}->{UPTIME}},
90+
{
91+
TIME => [$uptime],
92+
};
93+
}
94+
95+
1;

agent/Windows/uptime.vbs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'' Plugin for OCS Inventory NG 2.x
2+
'' Uptime 1.0.1 (04/05/2014)
3+
'' PRIOU Guillaume
4+
5+
Set objWMIService=GetObject("winmgmts:\\.\root\cimv2")
6+
Set colOperatingSystems=objWMIService.ExecQuery _
7+
("Select * From Win32_PerfFormattedData_PerfOS_System")
8+
For Each objOS in colOperatingSystems
9+
intSystemUptime=Int(objOS.SystemUpTime)
10+
TimedAt=FormatDateTime(Date(),2) &", " &FormatDateTime(Time(),4)
11+
Wscript.echo "<UPTIME>"
12+
Wscript.echo UpTime(intSystemUptime)
13+
Wscript.echo "</UPTIME>"
14+
next
15+
Function UpTime(S)
16+
M=S\60 : S=S mod 60 : H=M\60 : M=M mod 60 : D=H\24
17+
UpTime="<TIME>" & D &" Days, " & H MOD 24 & " Hours, " & M & " Minutes </TIME>"
18+
End Function

cd_uptime/cd_uptime.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
//====================================================================================
3+
// OCS INVENTORY REPORTS
4+
// Copyleft Erwan GOALOU 2010 (erwan(at)ocsinventory-ng(pt)org)
5+
// Web: http://www.ocsinventory-ng.org
6+
//
7+
// This code is open source and may be copied and modified as long as the source
8+
// code is always made freely available.
9+
// Please refer to the General Public Licence http://www.gnu.org/ or Licence.txt
10+
//====================================================================================
11+
12+
if(AJAX){
13+
parse_str($protectedPost['ocs']['0'], $params);
14+
$protectedPost+=$params;
15+
ob_start();
16+
$ajax = true;
17+
}
18+
else{
19+
$ajax=false;
20+
}
21+
print_item_header("UpTime");
22+
if (!isset($protectedPost['SHOW']))
23+
$protectedPost['SHOW'] = 'NOSHOW';
24+
$form_name="uptime";
25+
$table_name=$form_name;
26+
$tab_options=$protectedPost;
27+
$tab_options['form_name']=$form_name;
28+
$tab_options['table_name']=$table_name;
29+
echo open_form($form_name);
30+
$list_fields=array( 'uptime' => 'time',
31+
);
32+
$list_col_cant_del=$list_fields;
33+
$default_fields= $list_fields;
34+
$sql=prepare_sql_tab($list_fields);
35+
$sql['SQL'] .= "FROM uptime WHERE (hardware_id = $systemid)";
36+
array_push($sql['ARG'],$systemid);
37+
$tab_options['ARG_SQL']=$sql['ARG'];
38+
$tab_options['ARG_SQL_COUNT']=$systemid;
39+
ajaxtab_entete_fixe($list_fields,$default_fields,$tab_options,$list_col_cant_del);
40+
echo close_form();
41+
if ($ajax){
42+
ob_end_clean();
43+
tab_req($list_fields,$default_fields,$list_col_cant_del,$sql['SQL'],$tab_options);
44+
ob_start();
45+
}
46+
?>

install.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
function plugin_version_uptime()
3+
{
4+
return array('name' => 'uptime',
5+
'version' => '1.0',
6+
'author'=> 'Guillaume PRIOU, Gilles DUBOIS',
7+
'license' => 'GPLv2',
8+
'verMinOcs' => '2.2');
9+
}
10+
11+
function plugin_init_uptime()
12+
{
13+
$object = new plugins;
14+
$object -> add_cd_entry("uptime","other");
15+
16+
// Officepack table creation
17+
18+
$object -> sql_query("CREATE TABLE IF NOT EXISTS `uptime` (
19+
`ID` INT(11) NOT NULL AUTO_INCREMENT,
20+
`HARDWARE_ID` INT(11) NOT NULL,
21+
`TIME` VARCHAR(64) DEFAULT NULL,
22+
PRIMARY KEY (`ID`,`HARDWARE_ID`)
23+
) ENGINE=INNODB ;");
24+
25+
}
26+
27+
function plugin_delete_uptime()
28+
{
29+
$object = new plugins;
30+
$object -> del_cd_entry("uptime");
31+
32+
$object -> sql_query("DROP TABLE `uptime`;");
33+
34+
}
35+
36+
?>

0 commit comments

Comments
 (0)