-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First commit, plugin's initial revision
- Loading branch information
1 parent
06d3cae
commit b60e7fa
Showing
6 changed files
with
225 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
############################################################################### | ||
## OCSINVENTORY-NG | ||
## Copyleft Guillaume PROTET 2013 | ||
## Web : http://www.ocsinventory-ng.org | ||
## | ||
## This code is open source and may be copied and modified as long as the source | ||
## code is always made freely available. | ||
## Please refer to the General Public Licence http://www.gnu.org/ or Licence.txt | ||
################################################################################ | ||
|
||
package Apache::Ocsinventory::Plugins::Uptime::Map; | ||
|
||
use strict; | ||
|
||
use Apache::Ocsinventory::Map; | ||
#Plugin UPTIME | ||
$DATA_MAP{uptime} = { | ||
mask => 0, | ||
multi => 1, | ||
auto => 1, | ||
delOnReplace => 1, | ||
sortBy => 'TIME', | ||
writeDiff => 0, | ||
cache => 0, | ||
fields => { | ||
TIME => {}, | ||
} | ||
}; | ||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PerlModule Apache::Ocsinventory::Plugins::Uptime::Map; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
############################################################################### | ||
## OCSINVENTORY-NG | ||
## Copyleft Guillaume PROTET 2010 | ||
## Web : http://www.ocsinventory-ng.org | ||
## | ||
## This code is open source and may be copied and modified as long as the source | ||
## code is always made freely available. | ||
## Please refer to the General Public Licence http://www.gnu.org/ or Licence.txt | ||
################################################################################ | ||
|
||
package Ocsinventory::Agent::Modules::Uptime; | ||
|
||
sub new { | ||
|
||
my $name="uptime"; # Name of the module | ||
|
||
my (undef,$context) = @_; | ||
my $self = {}; | ||
|
||
#Create a special logger for the module | ||
$self->{logger} = new Ocsinventory::Logger ({ | ||
config => $context->{config} | ||
}); | ||
|
||
$self->{logger}->{header}="[$name]"; | ||
|
||
$self->{context}=$context; | ||
|
||
$self->{structure}= { | ||
name => $name, | ||
start_handler => undef, #or undef if don't use this hook | ||
prolog_writer => undef, #or undef if don't use this hook | ||
prolog_reader => undef, #or undef if don't use this hook | ||
inventory_handler => $name."_inventory_handler", #or undef if don't use this hook | ||
end_handler => undef #or undef if don't use this hook | ||
}; | ||
|
||
bless $self; | ||
} | ||
|
||
######### Hook methods ############ | ||
|
||
sub uptime_inventory_handler { | ||
|
||
my $self = shift; | ||
my $logger = $self->{logger}; | ||
|
||
my $common = $self->{context}->{common}; | ||
|
||
#I add the treatments for my new killer feature | ||
$logger->debug("Yeah you are in uptime_inventory_handler :)"); | ||
|
||
my $luptime = `cat /proc/uptime | awk '{print $1}'`; | ||
my $uptime = undef; | ||
|
||
# These help us calculate the minutes and hours | ||
my $min=60; | ||
my $hour = $min*60; | ||
my $day = $hour*24; | ||
|
||
my $minutes = 0; | ||
my $hours = 0; | ||
my $days = 0; | ||
|
||
# Make the uptime number integer | ||
my $seconds = int($luptime); | ||
|
||
while ($seconds >= $min) { | ||
while ($seconds >= $hour) { | ||
while ($seconds >= $day) { | ||
$seconds -= $day; | ||
++$days; | ||
} | ||
$seconds -= $hour; | ||
++$hours; | ||
} | ||
$seconds -= $min; | ||
++$minutes | ||
} | ||
if($seconds < 10) { $seconds = "0$seconds"; } | ||
if($minutes < 10) { $minutes = "0$minutes"; } | ||
if($hours < 10) {$hours = "0$hours"; } | ||
if($days < 10) {$days = "0$days"; } | ||
|
||
#print "$days:$hours:$minutes:$seconds"; | ||
|
||
$uptime = "$days days $hours hours $minutes minutes"; | ||
|
||
push @{$common->{xmltags}->{UPTIME}}, | ||
{ | ||
TIME => [$uptime], | ||
}; | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'' Plugin for OCS Inventory NG 2.x | ||
'' Uptime 1.0.1 (04/05/2014) | ||
'' PRIOU Guillaume | ||
|
||
Set objWMIService=GetObject("winmgmts:\\.\root\cimv2") | ||
Set colOperatingSystems=objWMIService.ExecQuery _ | ||
("Select * From Win32_PerfFormattedData_PerfOS_System") | ||
For Each objOS in colOperatingSystems | ||
intSystemUptime=Int(objOS.SystemUpTime) | ||
TimedAt=FormatDateTime(Date(),2) &", " &FormatDateTime(Time(),4) | ||
Wscript.echo "<UPTIME>" | ||
Wscript.echo UpTime(intSystemUptime) | ||
Wscript.echo "</UPTIME>" | ||
next | ||
Function UpTime(S) | ||
M=S\60 : S=S mod 60 : H=M\60 : M=M mod 60 : D=H\24 | ||
UpTime="<TIME>" & D &" Days, " & H MOD 24 & " Hours, " & M & " Minutes </TIME>" | ||
End Function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
//==================================================================================== | ||
// OCS INVENTORY REPORTS | ||
// Copyleft Erwan GOALOU 2010 (erwan(at)ocsinventory-ng(pt)org) | ||
// Web: http://www.ocsinventory-ng.org | ||
// | ||
// This code is open source and may be copied and modified as long as the source | ||
// code is always made freely available. | ||
// Please refer to the General Public Licence http://www.gnu.org/ or Licence.txt | ||
//==================================================================================== | ||
|
||
if(AJAX){ | ||
parse_str($protectedPost['ocs']['0'], $params); | ||
$protectedPost+=$params; | ||
ob_start(); | ||
$ajax = true; | ||
} | ||
else{ | ||
$ajax=false; | ||
} | ||
print_item_header("UpTime"); | ||
if (!isset($protectedPost['SHOW'])) | ||
$protectedPost['SHOW'] = 'NOSHOW'; | ||
$form_name="uptime"; | ||
$table_name=$form_name; | ||
$tab_options=$protectedPost; | ||
$tab_options['form_name']=$form_name; | ||
$tab_options['table_name']=$table_name; | ||
echo open_form($form_name); | ||
$list_fields=array( 'uptime' => 'time', | ||
); | ||
$list_col_cant_del=$list_fields; | ||
$default_fields= $list_fields; | ||
$sql=prepare_sql_tab($list_fields); | ||
$sql['SQL'] .= "FROM uptime WHERE (hardware_id = $systemid)"; | ||
array_push($sql['ARG'],$systemid); | ||
$tab_options['ARG_SQL']=$sql['ARG']; | ||
$tab_options['ARG_SQL_COUNT']=$systemid; | ||
ajaxtab_entete_fixe($list_fields,$default_fields,$tab_options,$list_col_cant_del); | ||
echo close_form(); | ||
if ($ajax){ | ||
ob_end_clean(); | ||
tab_req($list_fields,$default_fields,$list_col_cant_del,$sql['SQL'],$tab_options); | ||
ob_start(); | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
function plugin_version_uptime() | ||
{ | ||
return array('name' => 'uptime', | ||
'version' => '1.0', | ||
'author'=> 'Guillaume PRIOU, Gilles DUBOIS', | ||
'license' => 'GPLv2', | ||
'verMinOcs' => '2.2'); | ||
} | ||
|
||
function plugin_init_uptime() | ||
{ | ||
$object = new plugins; | ||
$object -> add_cd_entry("uptime","other"); | ||
|
||
// Officepack table creation | ||
|
||
$object -> sql_query("CREATE TABLE IF NOT EXISTS `uptime` ( | ||
`ID` INT(11) NOT NULL AUTO_INCREMENT, | ||
`HARDWARE_ID` INT(11) NOT NULL, | ||
`TIME` VARCHAR(64) DEFAULT NULL, | ||
PRIMARY KEY (`ID`,`HARDWARE_ID`) | ||
) ENGINE=INNODB ;"); | ||
|
||
} | ||
|
||
function plugin_delete_uptime() | ||
{ | ||
$object = new plugins; | ||
$object -> del_cd_entry("uptime"); | ||
|
||
$object -> sql_query("DROP TABLE `uptime`;"); | ||
|
||
} | ||
|
||
?> |