Sunday, August 18, 2013

FileEvent – Example 4 – Another multiple files count example

Introduction

The previous example showed how more than one matching file could be sent in a single call. The converse of this “max_send_count” option is also available – called “min_send_count”. This is used to indicate that no files should be sent unless at least the specified number of suitable files could be found.

Consider the following example configuration:

<?xml version="1.0" standalone="yes"?>
<FileEvent>
<settings>
  <db>/tmp/testing.db</db>
</settings>
  <event>
    <min_send_count>8</min_send_count>
    <max_send_count>10</max_send_count>
    <description>scp example4 transfer</description>
    <file_pattern>file1_%{4year}%{2month}%{2day}.txt</file_pattern>
   <directory>/home/venture/projects/SOURCE/fileevent/testing/example4</directory>
    <xfer_job_type>scp</xfer_job_type>
    <xfer_destination>test@lubuntu1:/tmp/%{f}</xfer_destination>
    <post_archive>true</post_archive>
  </event>
</FileEvent>

In this configuration the “min_send_count” has been set to 8 files, so if only 5 files exist then running it will actually transfer no files!

$ fileevent.pl --config example4.xml --verbose --action=process
2013/08/15 00:06:20.384 0000000-I Events to load from configuratione file: 1
2013/08/15 00:06:20.389 0000001-I Event #0 [scp example4 transfer] processing.
2013/08/15 00:06:20.390 0000002-E Maximum wait time for event #0 passed.
2013/08/15 00:06:20.390 0000003-E Only 5 files found, minimum of 8 required.
2013/08/15 00:06:20.391 0000004-E Errors encountered: 1

In such scenarios the return code is “1” indicating an error has occurred since no files could be sent.

Improving Alerting

This might be a good example scenario where you want to be alerted more directly rather than just see the process fail. This is also possible with FileEvent. For example consider the following configuration – an additional line has been added – shown in bold:


<?xml version="1.0" standalone="yes"?>
<FileEvent>
<settings>
  <db>/tmp/testing.db</db>
</settings>
  <event>
    <alert_when_missing>venture@localhost</alert_when_missing>
    <min_send_count>8</min_send_count>
    <max_send_count>10</max_send_count>
    <description>scp example4 transfer</description>
    <file_pattern>file1_%{4year}%{2month}%{2day}.txt</file_pattern>
    <directory>/home/venture/projects/SOURCE/fileevent/testing/example4</directo ry>
    <xfer_job_type>scp</xfer_job_type>
    <xfer_destination>test@lubuntu1:/tmp/%{f}</xfer_destination>
    <post_archive>true</post_archive>
  </event>
</FileEvent>

Try running the process with just 5 files available again now:

$ fileevent.pl --config example4-2.xml --verbose --action=process
2013/08/15 00:23:24.445 0000000-I Events to load from configuratione file: 1
2013/08/15 00:23:24.450 0000001-I Event #0 [scp example4 transfer] processing.
2013/08/15 00:23:24.470 0000002-I Email sent to venture@localhost (missing files).
2013/08/15 00:23:24.470 0000003-E Maximum wait time for event #0 passed.
2013/08/15 00:23:24.470 0000004-E Only 5 files found, minimum of 8 required.
2013/08/15 00:23:24.470 0000005-E Errors encountered: 1


Notice that an email notification has been sent now indicating the cause of the problem - which is often more useful than just a failure code!


No comments:

Post a Comment