| 1 | #!/usr/bin/perl | ||
| 2 | |||
| 3 | package JMX::Jmx4Perl::J4psh::Command::Server; | ||
| 4 | use strict; | ||
| 5 | use Term::ANSIColor qw(:constants); | ||
| 6 | |||
| 7 | use base qw(JMX::Jmx4Perl::J4psh::Command); | ||
| 8 | |||
| 9 | |||
| 10 | =head1 NAME | ||
| 11 | |||
| 12 | JMX::Jmx4Perl::J4psh::Command::Server - Server related commands | ||
| 13 | |||
| 14 | =head1 DESCRIPTION | ||
| 15 | |||
| 16 | =head1 COMMANDS | ||
| 17 | |||
| 18 | =over | ||
| 19 | |||
| 20 | =cut | ||
| 21 | |||
| 22 | |||
| 23 | sub name { "server" } | ||
| 24 | |||
| 25 | sub top_commands { | ||
| 26 | my $self = shift; | ||
| 27 | return { | ||
| 28 | "servers" => { | ||
| 29 | desc => "Show all configured servers", | ||
| 30 | proc => $self->cmd_server_list, | ||
| 31 | doc => <<EOT | ||
| 32 | List all servers stored in the configuration | ||
| 33 | and those connected during this session | ||
| 34 | (indicated by a '*') | ||
| 35 | EOT | ||
| 36 | } | ||
| 37 | }; | ||
| 38 | } | ||
| 39 | |||
| 40 | sub global_commands { | ||
| 41 | my $self = shift; | ||
| 42 | return { | ||
| 43 | "connect" => { | ||
| 44 | desc => "Connect to a server by its URL or symbolic name", | ||
| 45 | minargs => 1, maxargs => 2, | ||
| 46 | args => $self->complete->servers, | ||
| 47 | proc => $self->cmd_connect, | ||
| 48 | doc => <<EOT | ||
| 49 | |||
| 50 | connect <url or name> [<name>] | ||
| 51 | |||
| 52 | Connect to an agent. <url> is the URL under which the agent | ||
| 53 | is reachable. Alternatively a <name> as stored in the configuration | ||
| 54 | can be given. Is using the <url> form an additional <name> | ||
| 55 | can be given which will be used as name in the server list. | ||
| 56 | EOT | ||
| 57 | } | ||
| 58 | }; | ||
| 59 | } | ||
| 60 | |||
| 61 | # Connect to a server | ||
| 62 | sub cmd_connect { | ||
| 63 | my $self = shift; | ||
| 64 | return sub { | ||
| 65 | my $arg = shift; | ||
| 66 | my $name = shift; | ||
| 67 | my $context = $self->context; | ||
| 68 | $context->servers->connect_to_server($arg,$name); | ||
| 69 | $context->commands->reset_stack; | ||
| 70 | my ($yellow,$reset) = $context->color("host",RESET); | ||
| 71 | print "Connected to " . $yellow . $context->server . $reset . " (" . $context->agent->url . ").\n" if $context->agent; | ||
| 72 | } | ||
| 73 | } | ||
| 74 | |||
| 75 | # Show all servers | ||
| 76 | sub cmd_server_list { | ||
| 77 | my $self = shift; | ||
| 78 | return sub { | ||
| 79 | my $context = $self->context; | ||
| 80 | my $server_list = $context->servers->list; | ||
| 81 | for my $s (@$server_list) { | ||
| 82 | my ($ms,$me) = $context->color("host",RESET); | ||
| 83 | my $sep = $s->{from_config} ? "-" : "*"; | ||
| 84 | printf " " . $ms . '%30.30s' . $me . ' %s %s' . "\n",$s->{name},$sep,$s->{url}; | ||
| 85 | } | ||
| 86 | } | ||
| 87 | } | ||
| 88 | |||
| 89 | =back | ||
| 90 | |||
| 91 | =head1 LICENSE | ||
| 92 | |||
| 93 | This file is part of jmx4perl. | ||
| 94 | |||
| 95 | Jmx4perl is free software: you can redistribute it and/or modify | ||
| 96 | it under the terms of the GNU General Public License as published by | ||
| 97 | the Free Software Foundation, either version 2 of the License, or | ||
| 98 | (at your option) any later version. | ||
| 99 | |||
| 100 | jmx4perl is distributed in the hope that it will be useful, | ||
| 101 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 102 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 103 | GNU General Public License for more details. | ||
| 104 | |||
| 105 | You should have received a copy of the GNU General Public License | ||
| 106 | along with jmx4perl. If not, see <http://www.gnu.org/licenses/>. | ||
| 107 | |||
| 108 | A commercial license is available as well. Please contact roland@cpan.org for | ||
| 109 | further details. | ||
| 110 | |||
| 111 | =head1 PROFESSIONAL SERVICES | ||
| 112 | |||
| 113 | Just in case you need professional support for this module (or Nagios or JMX in | ||
| 114 | general), you might want to have a look at | ||
| 115 | http://www.consol.com/opensource/nagios/. Contact roland.huss@consol.de for | ||
| 116 | further information (or use the contact form at http://www.consol.com/contact/) | ||
| 117 | |||
| 118 | =head1 AUTHOR | ||
| 119 | |||
| 120 | roland@cpan.org | ||
| 121 | |||
| 122 | =cut | ||
| 123 | |||
| 124 | 1; | ||
| 125 |