changed paths of DNS cache (now in /var/cache) and dumped packets; dump only if ...
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Thu, 28 May 2015 13:01:51 +0000 (15:01 +0200)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Thu, 28 May 2015 13:01:51 +0000 (15:01 +0200)
src/config/option/dnscachefileoption.cpp
src/icmp/icmppacketfactory.cpp

index 3dd97d3..d4c910c 100644 (file)
@@ -39,7 +39,7 @@ using I2n::Logger::GlobalLogger;
 DnsCacheFileOption::DnsCacheFileOption() :
     ConfigurationOption(
         "dns-cache-file",
-        value<string>()->default_value( "/etc/pingcheck_dns_cache.xml" ),
+        value<string>()->default_value( "/var/cache/pingcheck_dns_cache.xml" ),
         "Name of the DNS cache file."
     )
 {
index 5024789..ae972fa 100644 (file)
@@ -33,6 +33,7 @@
 #include <boost/scoped_array.hpp>
 
 #include <logfunc.hpp>
+#include <filefunc.hxx>
 #include <tmpfstream.hpp>
 
 #include "boost_assert_handler.h"
@@ -51,8 +52,9 @@ using I2n::Logger::GlobalLogger;
 //-----------------------------------------------------------------------------
 
 // set default value
-DumpMode    IcmpPacketFactory::PacketDumpMode = DUMP_IF_ERROR;
-std::string IcmpPacketFactory::DumpFilePrefix = "/tmp/icmp_";
+DumpMode    IcmpPacketFactory::PacketDumpMode = DUMP_ALWAYS; //DUMP_IF_ERROR;
+std::string IcmpPacketFactory::DumpFilePrefix =
+                                            "/datastore/pingcheck.broken/icmp_";
 
 /**
  * @brief Creates an ICMP packet from the input stream @c std::istream.
@@ -202,6 +204,14 @@ void IcmpPacketFactory::dump_packet(const std::string &data)
     std::stringstream temp_name;
     temp_name << DumpFilePrefix << capture_time << ".pcap.XXXXXX";
 
+    // check if directory exists
+    if ( !I2n::path_exists( I2n::dirname(temp_name.str()) ) )
+    {
+        GlobalLogger.debug() << "Not saving packet data because directory "
+            << I2n::dirname(temp_name.str()) << " does not exist";
+        return;
+    }
+
     // open file
     I2n::tmpfstream temp_stream;
     if ( !temp_stream.open(temp_name.str()) )
@@ -227,6 +237,14 @@ void IcmpPacketFactory::dump_packet(const IcmpPacket &packet)
     std::stringstream temp_name;
     temp_name << DumpFilePrefix << capture_time << ".pcap.XXXXXX";
 
+    // check if directory exists
+    if ( !I2n::path_exists( I2n::dirname(temp_name.str()) ) )
+    {
+        GlobalLogger.debug() << "Not saving packet data because directory "
+            << I2n::dirname(temp_name.str()) << " does not exist";
+        return;
+    }
+
     // open file
     I2n::tmpfstream temp_stream;
     if ( !temp_stream.open(temp_name.str()) )