ADD: script to update agent table in ossec database
This commit is contained in:
parent
07bc45ec8d
commit
05ed5692c8
59
bin/ossec-update-agents-database.pl
Normal file
59
bin/ossec-update-agents-database.pl
Normal file
@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
#ABSTRACT: script to update the agents within the mysql database
|
||||
#PODNAME: ossec-update-agents-database.pl
|
||||
use strict;
|
||||
use warnings;
|
||||
use File::Basename;
|
||||
use OSSEC;
|
||||
use XML::LibXML;
|
||||
use Try::Tiny;
|
||||
|
||||
my $ossec = OSSEC->new();
|
||||
my $mysql = $ossec->mysql();
|
||||
|
||||
# clear rules from database
|
||||
$mysql->deleteAllAgents();
|
||||
|
||||
my $help = readpipe($ossec->ossecPath()."/bin/agent_control -l");
|
||||
my @lines = split /\n/, $help;
|
||||
|
||||
|
||||
for my $l (@lines)
|
||||
{
|
||||
if ($l =~ /^\s*ID:\s(\d+)/)
|
||||
{
|
||||
my $help = readpipe($ossec->ossecPath()."/bin/agent_control -i $1");
|
||||
my @lines = split /\n/, $help;
|
||||
my $name;
|
||||
my $ip;
|
||||
my $version;
|
||||
my $information;
|
||||
|
||||
for my $l2 (@lines)
|
||||
{
|
||||
if ($l2 =~ /Name:\s+(\S+)/)
|
||||
{
|
||||
$name = $1;
|
||||
}
|
||||
|
||||
if ($l2 =~ /IP.*:\s+(\S+)/)
|
||||
{
|
||||
$ip = $1;
|
||||
}
|
||||
|
||||
if ($l2 =~ /version:\s+OSSEC\sHIDS\sv(\S+)/)
|
||||
{
|
||||
$version = $1;
|
||||
}
|
||||
|
||||
if ($l2 =~ /system:\s+(.*)$/)
|
||||
{
|
||||
$information=$1;
|
||||
}
|
||||
}
|
||||
|
||||
$mysql->addAgent("1", 0, $ip, $version,$name, $information );
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user