| 1 | #!/usr/bin/perl | ||
| 2 | |||
| 3 | package JMX::Jmx4Perl::J4psh::Command::Global; | ||
| 4 | use strict; | ||
| 5 | use Term::ANSIColor qw(:constants); | ||
| 6 | use Term::Clui; | ||
| 7 | use base qw(JMX::Jmx4Perl::J4psh::Command); | ||
| 8 | |||
| 9 | =head1 NAME | ||
| 10 | |||
| 11 | JMX::Jmx4Perl::J4psh::Command::Global - Globally available commands | ||
| 12 | |||
| 13 | =head1 DESCRIPTION | ||
| 14 | |||
| 15 | =head1 COMMANDS | ||
| 16 | |||
| 17 | =over | ||
| 18 | |||
| 19 | =cut | ||
| 20 | |||
| 21 | |||
| 22 | sub name { "global" } | ||
| 23 | |||
| 24 | sub global_commands { | ||
| 25 | my $self = shift; | ||
| 26 | |||
| 27 | return | ||
| 28 | { | ||
| 29 | "error" => { | ||
| 30 | desc => "Show last error (if any)", | ||
| 31 | proc => $self->cmd_last_error, | ||
| 32 | doc => <<EOT | ||
| 33 | Show the last error, if any occured. Including all | ||
| 34 | stacktraces returned by the server. | ||
| 35 | EOT | ||
| 36 | }, | ||
| 37 | "help" => { | ||
| 38 | desc => "Print online help", | ||
| 39 | args => sub { shift->help_args(undef, @_); }, | ||
| 40 | method => sub { shift->help_call(undef, @_); }, | ||
| 41 | doc => <<EOT, | ||
| 42 | help [<command>] | ||
| 43 | h [<command>] | ||
| 44 | |||
| 45 | Print online help. Without option, show a summary. With | ||
| 46 | option, show specific help for command <command>. | ||
| 47 | EOT | ||
| 48 | }, | ||
| 49 | "h" => { alias => "help", exclude_from_completion=>1}, | ||
| 50 | "history" => { | ||
| 51 | desc => "Command History", | ||
| 52 | doc => <<EOT, | ||
| 53 | |||
| 54 | history [-c] [-d <num>] | ||
| 55 | |||
| 56 | Specify a number to list the last N lines of history | ||
| 57 | |||
| 58 | Options: | ||
| 59 | -c : Clear the command history | ||
| 60 | -d <num> : Delete a single item <num> | ||
| 61 | EOT | ||
| 62 | args => "[-c] [-d] [number]", | ||
| 63 | method => sub { shift->history_call(@_) }, | ||
| 64 | }, | ||
| 65 | "quit" => { | ||
| 66 | desc => "Quit", | ||
| 67 | maxargs => 0, | ||
| 68 | method => sub { shift->exit_requested(1); }, | ||
| 69 | doc => <<EOT, | ||
| 70 | Quit shell. | ||
| 71 | EOT | ||
| 72 | }, | ||
| 73 | "q" => { alias => 'quit', exclude_from_completion => 1 }, | ||
| 74 | "exit" => { alias => 'quit', exclude_from_completion => 1 } | ||
| 75 | }; | ||
| 76 | } | ||
| 77 | |||
| 78 | sub cmd_last_error { | ||
| 79 | my $self = shift; | ||
| 80 | return sub { | ||
| 81 | my $agent = $self->agent; | ||
| 82 | my $txt = $self->context->last_error; | ||
| 83 | if ($txt) { | ||
| 84 | chomp $txt; | ||
| 85 | print "$txt\n"; | ||
| 86 | } else { | ||
| 87 | print "No errors\n"; | ||
| 88 | } | ||
| 89 | } | ||
| 90 | } | ||
| 91 | |||
| 92 | =back | ||
| 93 | |||
| 94 | =head1 LICENSE | ||
| 95 | |||
| 96 | This file is part of jmx4perl. | ||
| 97 | |||
| 98 | Jmx4perl is free software: you can redistribute it and/or modify | ||
| 99 | it under the terms of the GNU General Public License as published by | ||
| 100 | the Free Software Foundation, either version 2 of the License, or | ||
| 101 | (at your option) any later version. | ||
| 102 | |||
| 103 | jmx4perl is distributed in the hope that it will be useful, | ||
| 104 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 105 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 106 | GNU General Public License for more details. | ||
| 107 | |||
| 108 | You should have received a copy of the GNU General Public License | ||
| 109 | along with jmx4perl. If not, see <http://www.gnu.org/licenses/>. | ||
| 110 | |||
| 111 | A commercial license is available as well. Please contact roland@cpan.org for | ||
| 112 | further details. | ||
| 113 | |||
| 114 | =head1 PROFESSIONAL SERVICES | ||
| 115 | |||
| 116 | Just in case you need professional support for this module (or Nagios or JMX in | ||
| 117 | general), you might want to have a look at | ||
| 118 | http://www.consol.com/opensource/nagios/. Contact roland.huss@consol.de for | ||
| 119 | further information (or use the contact form at http://www.consol.com/contact/) | ||
| 120 | |||
| 121 | =head1 AUTHOR | ||
| 122 | |||
| 123 | roland@cpan.org | ||
| 124 | |||
| 125 | =cut | ||
| 126 | |||
| 127 | 1; | ||
| 128 |