[Bps-public-commit] app-wsgetmail branch additional-diagnostic-patch created. 0.08-1-gdc6fd01

BPS Git Server git at git.bestpractical.com
Tue Nov 22 15:47:57 UTC 2022


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "app-wsgetmail".

The branch, additional-diagnostic-patch has been created
        at  dc6fd01d735762cbe1f6391d97a3813201e25a22 (commit)

- Log -----------------------------------------------------------------
commit dc6fd01d735762cbe1f6391d97a3813201e25a22
Author: Brian Conry <bconry at bestpractical.com>
Date:   Fri Nov 18 09:49:56 2022 -0600

    Add response header logging with debug on failure
    
    A customer working with MS support was requested to provide response
    header information for troubleshooting an issue.  This information was
    not previously logged.
    
    This is currently being treated as a one-off patch and not necessarily a
    permanent new feature.  As a new feature it may be desirable to add
    debug levels or content flags.

diff --git a/lib/App/wsgetmail.pm b/lib/App/wsgetmail.pm
index b4c7aaa..181dfc7 100644
--- a/lib/App/wsgetmail.pm
+++ b/lib/App/wsgetmail.pm
@@ -48,6 +48,9 @@
 
 use v5.10;
 
+require POSIX;
+require Time::HiRes;
+
 package App::wsgetmail;
 
 use Moo;
@@ -215,7 +218,7 @@ sub process_message {
         $ok = $self->post_fetch_action($message);
     }
     if ($self->config->{dump_messages}) {
-        warn "dumped message in file $filename" if ($self->config->{debug});
+        warn get_logging_timestamp() . " dumped message in file $filename" if ($self->config->{debug});
     }
     else {
         unlink $filename or warn "couldn't delete message file $filename : $!";
@@ -266,6 +269,21 @@ sub _build_mda {
     return App::wsgetmail::MDA->new($config);
 }
 
+###
+
+=head1 PACKAGE FUNCTIONS
+
+=head2 get_logging_timestamp
+
+Returns an ISO 8601 timestamp suitable for logs using UTC.
+
+=cut
+
+sub get_logging_timestamp {
+    my ($s, $ms) = Time::HiRes::gettimeofday();
+    return POSIX::strftime( sprintf( '%%Y-%%m-%%dT%%H:%%M:%%S.%06.6dZ', $ms ), gmtime( $s ) );
+}
+
 =head1 CONFIGURATION
 
 =head2 Configuring Microsoft 365 Client Access
diff --git a/lib/App/wsgetmail/MDA.pm b/lib/App/wsgetmail/MDA.pm
index 0f46960..42ca470 100644
--- a/lib/App/wsgetmail/MDA.pm
+++ b/lib/App/wsgetmail/MDA.pm
@@ -195,7 +195,7 @@ sub _run_command {
     open my $fh, "<$filename"  or die $!;
     my ($input, $output, $error);
     unless ($self->command) {
-        warn "no action to delivery message, command option is empty or null" if ($self->debug);
+        warn App::wsgetmail::get_logging_timestamp() . " no action to delivery message, command option is empty or null" if ($self->debug);
         return 1;
     }
 
@@ -205,7 +205,7 @@ sub _run_command {
                      $self->command,
                      ($self->debug ? join(' ', _split_command_args($self->command_args)) : '' ),
                      $filename, $?);
-        warn "output : $output\nerror:$error\n" if ($self->debug);
+        warn App::wsgetmail::get_logging_timestamp() . " output : $output\nerror:$error\n" if ($self->debug);
     }
     close $fh;
     return $ok;
diff --git a/lib/App/wsgetmail/MS365.pm b/lib/App/wsgetmail/MS365.pm
index d17e30a..686df96 100644
--- a/lib/App/wsgetmail/MS365.pm
+++ b/lib/App/wsgetmail/MS365.pm
@@ -302,7 +302,8 @@ sub get_message_mime_content {
     my $response = $self->_client->get_request([@path_parts]);
     unless ($response->is_success) {
         warn "failed to fetch message $message_id " . $response->status_line;
-        warn "response from server : " . $response->content if $self->debug;
+        warn App::wsgetmail::get_logging_timestamp() . " response headers from server : " . $response->headers if $self->debug;
+        warn App::wsgetmail::get_logging_timestamp() . " response from server : " . $response->content if $self->debug;
         return undef;
     }
 
@@ -326,7 +327,8 @@ sub delete_message {
     my $response = $self->_client->delete_request([@path_parts]);
     unless ($response->is_success) {
         warn "failed to delete message " . $response->status_line;
-        warn "response from server : " . $response->content if $self->debug;
+        warn App::wsgetmail::get_logging_timestamp() . " response headers from server : " . $response->headers if $self->debug;
+        warn App::wsgetmail::get_logging_timestamp() . " response from server : " . $response->content if $self->debug;
     }
 
     return $response;
@@ -346,7 +348,8 @@ sub mark_message_as_read {
                                                   Content => encode_json({isRead => $JSON::true }) });
     unless ($response->is_success) {
         warn "failed to mark message as read " . $response->status_line;
-        warn "response from server : " . $response->content if $self->debug;
+        warn App::wsgetmail::get_logging_timestamp() . " response headers from server : " . $response->headers if $self->debug;
+        warn App::wsgetmail::get_logging_timestamp() . " response from server : " . $response->content if $self->debug;
     }
 
     return $response;
@@ -368,7 +371,8 @@ sub get_folder_details {
     );
     unless ($response->is_success) {
         warn "failed to fetch folder detail " . $response->status_line;
-        warn "response from server : " . $response->content if $self->debug;
+        warn App::wsgetmail::get_logging_timestamp() . " response headers from server : " . $response->headers if $self->debug;
+        warn App::wsgetmail::get_logging_timestamp() . " response from server : " . $response->content if $self->debug;
         return undef;
     }
 
@@ -389,7 +393,8 @@ sub _fetch_messages {
         my $response = $self->_client->get_request_by_url($self->_next_fetch_url);
         unless ($response->is_success) {
             warn "failed to fetch messages " . $response->status_line;
-            warn "response from server : " . $response->content if $self->debug;
+            warn App::wsgetmail::get_logging_timestamp() . " response headers from server : " . $response->headers if $self->debug;
+            warn App::wsgetmail::get_logging_timestamp() . " response from server : " . $response->content if $self->debug;
             $self->_have_messages_to_fetch(0);
             return 0;
         }
@@ -439,7 +444,8 @@ sub _get_message_list {
 
     unless ($response->is_success) {
         warn "failed to fetch messages " . $response->status_line;
-        warn "response from server : " . $response->content if $self->debug;
+        warn App::wsgetmail::get_logging_timestamp() . " response headers from server : " . $response->headers if $self->debug;
+        warn App::wsgetmail::get_logging_timestamp() . " response from server : " . $response->content if $self->debug;
         return { value => [ ] };
     }
 
diff --git a/lib/App/wsgetmail/MS365/Client.pm b/lib/App/wsgetmail/MS365/Client.pm
index adc175a..20b8683 100644
--- a/lib/App/wsgetmail/MS365/Client.pm
+++ b/lib/App/wsgetmail/MS365/Client.pm
@@ -221,7 +221,7 @@ sub get_request {
     my ($self, $parts, $params) = @_;
     # add error handling!
     my $uri = URI->new($self->build_rest_uri(@$parts));
-    warn "making GET request to url $uri" if ($self->debug);
+    warn App::wsgetmail::get_logging_timestamp() . " making GET request to url $uri" if ($self->debug);
     $uri->query_form($params) if ($params);
     return $self->_ua->get($uri);
 }
@@ -234,7 +234,7 @@ Makes a GET request to the URL in the C<$url> string.
 
 sub get_request_by_url {
     my ($self, $url) = @_;
-    warn "making GET request to url $url" if ($self->debug);
+    warn App::wsgetmail::get_logging_timestamp() . " making GET request to url $url" if ($self->debug);
     return $self->_ua->get($url);
 }
 
@@ -248,7 +248,7 @@ strings with the specific endpoint to request. C<$params> is unused.
 sub delete_request {
     my ($self, $parts, $params) = @_;
     my $url = $self->build_rest_uri(@$parts);
-    warn "making DELETE request to url $url" if ($self->debug);
+    warn App::wsgetmail::get_logging_timestamp() . " making DELETE request to url $url" if ($self->debug);
     return $self->_ua->delete($url);
 }
 
@@ -263,7 +263,7 @@ reference to an array or hash of data to include in the POST request body.
 sub post_request {
     my ($self, $path_parts, $post_data) = @_;
     my $url = $self->build_rest_uri(@$path_parts);
-    warn "making POST request to url $url" if ($self->debug);
+    warn App::wsgetmail::get_logging_timestamp() . " making POST request to url $url" if ($self->debug);
     return $self->_ua->post($url,$post_data);
 }
 
@@ -278,7 +278,7 @@ a hashref of data to include in the PATCH request body.
 sub patch_request {
      my ($self, $path_parts, $patch_params) = @_;
      my $url = $self->build_rest_uri(@$path_parts);
-     warn "making PATCH request to url $url" if ($self->debug);
+     warn App::wsgetmail::get_logging_timestamp() . " making PATCH request to url $url" if ($self->debug);
      return $self->_ua->patch($url,%$patch_params);
  }
 
@@ -287,7 +287,7 @@ sub patch_request {
 sub _build_authorised_ua {
     my $self = shift;
     my $ua = $self->_new_useragent;
-    warn "getting system access token" if ($self->debug);
+    warn App::wsgetmail::get_logging_timestamp() . " getting system access token" if ($self->debug);
     $ua->default_header( Authorization => $self->_access_token() );
     return $ua;
 }
@@ -308,7 +308,7 @@ sub _get_user_access_token {
     my $self = shift;
     my $ua = $self->_new_useragent;
     my $access_token;
-    warn "getting user access token" if ($self->debug);
+    warn App::wsgetmail::get_logging_timestamp() . " getting user access token" if ($self->debug);
     my $oauth_login_url = sprintf('https://login.windows.net/%s/oauth2/token', $self->tenant_id);
     my $response = $ua->post( $oauth_login_url,
                               {
@@ -328,7 +328,7 @@ sub _get_user_access_token {
     }
     else {
         # throw error
-        warn "auth response from server : $raw_message" if ($self->debug);
+        warn App::wsgetmail::get_logging_timestamp() . " auth response from server : $raw_message" if ($self->debug);
         die sprintf('unable to get user access token for user %s request failed with status %s ', $self->username, $response->status_line);
     }
     return $access_token;

-----------------------------------------------------------------------


hooks/post-receive
-- 
app-wsgetmail


More information about the Bps-public-commit mailing list