From d63bc8c9d1c55fe9b4cf912c2d47aa038415f516 Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Wed, 10 Apr 2013 17:03:27 -0600 Subject: [PATCH] Make Agent.username and .hostname optional so they can be loaded from a minimal agent file and updated at runtime. --- bin/pt-agent | 8 ++++++-- lib/Percona/WebAPI/Resource/Agent.pm | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/bin/pt-agent b/bin/pt-agent index f2c929f9..ef0e974f 100755 --- a/bin/pt-agent +++ b/bin/pt-agent @@ -1247,14 +1247,18 @@ has 'uuid' => ( has 'username' => ( is => 'rw', isa => 'Str', - required => 1, + required => 0, default => sub { return $ENV{USER} || $ENV{LOGNAME} }, ); has 'hostname' => ( is => 'rw', isa => 'Str', - required => 1, + required => 0, + default => sub { + chomp(my $hostname = `hostname`); + return $hostname; + }, ); has 'alias' => ( diff --git a/lib/Percona/WebAPI/Resource/Agent.pm b/lib/Percona/WebAPI/Resource/Agent.pm index d5112645..f73816fd 100644 --- a/lib/Percona/WebAPI/Resource/Agent.pm +++ b/lib/Percona/WebAPI/Resource/Agent.pm @@ -31,14 +31,18 @@ has 'uuid' => ( has 'username' => ( is => 'rw', isa => 'Str', - required => 1, + required => 0, default => sub { return $ENV{USER} || $ENV{LOGNAME} }, ); has 'hostname' => ( is => 'rw', isa => 'Str', - required => 1, + required => 0, + default => sub { + chomp(my $hostname = `hostname`); + return $hostname; + }, ); has 'alias' => (