X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=perl%2FAmanda%2FLogfile.swg;h=a461adb3216a1086e42b3e4abeb6f0be96d86487;hb=refs%2Ftags%2Fupstream%2F3.3.3;hp=ba04a02c99c59d6aabb61aeaa5d5203d42efd8b6;hpb=fd48f3e498442f0cbff5f3606c7c403d0566150e;p=debian%2Famanda diff --git a/perl/Amanda/Logfile.swg b/perl/Amanda/Logfile.swg index ba04a02..a461adb 100644 --- a/perl/Amanda/Logfile.swg +++ b/perl/Amanda/Logfile.swg @@ -1,9 +1,10 @@ /* - * Copyright (c) 2007, 2008, 2009, 2010 Zmanda, Inc. All Rights Reserved. + * Copyright (c) 2007-2012 Zmanda, Inc. All Rights Reserved. * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 as published - * by the Free Software Foundation. + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY @@ -35,7 +36,7 @@ amglue_export_ok( open_logfile get_logline close_logfile - log_add + log_add log_add_full ); @@ -76,6 +77,7 @@ amglue_add_constant(P_AMDUMP, program_t); amglue_add_constant(P_AMIDXTAPED, program_t); amglue_add_constant(P_AMFETCHDUMP, program_t); amglue_add_constant(P_AMCHECKDUMP, program_t); +amglue_add_constant(P_AMVAULT, program_t); amglue_copy_to_tag(program_t, constants); /* TODO: support for writing logfiles is omitted for the moment. */ @@ -115,13 +117,20 @@ typedef int LOGLINE_RETURN; LOGLINE_RETURN get_logline(FILE *logfile); %rename(log_add) log_add_; +%rename(log_add_full) log_add_full_; %inline %{ static void log_add_(logtype_t typ, char *message) { log_add(typ, "%s", message); } +static void log_add_full_(logtype_t typ, char *pname, char *message) +{ + log_add_full(typ, pname, "%s", message); +} %} +void log_rename(char *datestamp); + typedef struct { %extend { /* destructor */ @@ -133,6 +142,7 @@ typedef struct { %immutable; char *timestamp; + char *write_timestamp; char *hostname; char *diskname; int level; @@ -144,6 +154,7 @@ typedef struct { int partnum; int totalparts; double sec; + off_t bytes; off_t kb; off_t orig_kb; %mutable; @@ -240,8 +251,7 @@ typedef struct { } amglue_export_ok( - find_log search_logfile dumps_match - match_host match_disk match_datestamp match_level + find_log search_logfile dumps_match log_rename ); char **find_log(void); @@ -279,13 +289,6 @@ find_result_t *dumps_match_dumpspecs(find_result_t *output_find, amglue_dumpspec_list *dumpspecs, gboolean ok); -/* these are actually available for clients as well, but they do not deserve - * their own perl module, so they're stuck here */ -gboolean match_host(char *pat, char *value); -gboolean match_disk(char *pat, char *value); -gboolean match_datestamp(char *pat, char *value); -gboolean match_level(char *pat, char *value); - %immutable; amanda_log_handler_t *amanda_log_trace_log; %mutable; @@ -296,6 +299,8 @@ amglue_export_ok( amglue_export_ok( find_all_logs find_latest_log + get_current_log_timestamp + make_stats ); %perlcode %{ @@ -317,4 +322,47 @@ sub find_latest_log return $logs[-1]; } +use Amanda::Config; +use Amanda::Debug; + +sub get_current_log_timestamp +{ + my $logfile = Amanda::Config::config_dir_relative( + Amanda::Config::getconf($Amanda::Config::CNF_LOGDIR)) . "/log"; + if (! -f $logfile) { + Amanda::Debug::warning("no current logfile '$logfile'"); + return undef; + } + + my $logh = open_logfile("$logfile"); + if (!$logh) { + Amanda::Debug::warning("could not open logfile '$logfile'"); + return undef; + } + while (my ($type, $prog, $str) = get_logline($logh)) { + if ($type == $L_START) { + my ($ts) = ($str =~ /date (\d+)/); + return $ts if $ts; + } + } + + # no timestamp, apparently + Amanda::Debug::warning("no current timestamp found in logfile"); + return undef; +} + +sub make_stats { + my ($size, $duration, $orig_kb) = @_; + + $duration = 0.1 if $duration <= 0; # prevent division by zero + my $kb = $size/1024; + my $kps = "$kb.0"/$duration; # Perlish cast from BigInt to float + + if (defined $orig_kb) { + return sprintf("[sec %f bytes %s kps %f orig-kb %s]", $duration, $size, $kps, $orig_kb); + } else { + return sprintf("[sec %f bytes %s kps %f]", $duration, $size, $kps); + } +} + %}