Ejemplo n.º 1
0
    def testGetFormattedField(self):
        """Tests the GetFormattedField function."""
        output_mediator = self._CreateOutputMediator()
        dynamic_fields_helper = dynamic.DynamicFieldsHelper(output_mediator)

        event = TestEvent()
        zone_string = dynamic_fields_helper.GetFormattedField(event, 'zone')
        self.assertEqual(zone_string, 'UTC')
Ejemplo n.º 2
0
    def testFormatSourceShort(self):
        """Tests the _FormatSourceShort function."""
        output_mediator = self._CreateOutputMediator()
        dynamic_fields_helper = dynamic.DynamicFieldsHelper(output_mediator)

        event = TestEvent()
        source_short_string = dynamic_fields_helper._FormatSourceShort(event)
        self.assertEqual(source_short_string, 'LOG')
Ejemplo n.º 3
0
    def testFormatInode(self):
        """Tests the _FormatInode function."""
        output_mediator = self._CreateOutputMediator()
        dynamic_fields_helper = dynamic.DynamicFieldsHelper(output_mediator)

        event = TestEvent()
        inode_string = dynamic_fields_helper._FormatInode(event)
        self.assertEqual(inode_string, '-')
Ejemplo n.º 4
0
    def testFormatMACB(self):
        """Tests the _FormatMACB function."""
        output_mediator = self._CreateOutputMediator()
        dynamic_fields_helper = dynamic.DynamicFieldsHelper(output_mediator)

        event = TestEvent()
        macb_string = dynamic_fields_helper._FormatMACB(event)
        self.assertEqual(macb_string, '..C.')
Ejemplo n.º 5
0
    def testFormatInode(self):
        """Tests the _FormatInode function."""
        output_mediator = self._CreateOutputMediator()
        dynamic_fields_helper = dynamic.DynamicFieldsHelper(output_mediator)

        event, event_data = containers_test_lib.CreateEventFromValues(
            self._TEST_EVENTS[0])
        inode_string = dynamic_fields_helper._FormatInode(event, event_data)
        self.assertEqual(inode_string, '-')
Ejemplo n.º 6
0
    def testFormatTimestampDescription(self):
        """Tests the _FormatTimestampDescription function."""
        output_mediator = self._CreateOutputMediator()
        dynamic_fields_helper = dynamic.DynamicFieldsHelper(output_mediator)

        event = TestEvent()
        timestamp_description_string = (
            dynamic_fields_helper._FormatTimestampDescription(event))
        self.assertEqual(timestamp_description_string,
                         'Metadata Modification Time')
Ejemplo n.º 7
0
    def testGetFormattedField(self):
        """Tests the GetFormattedField function."""
        output_mediator = self._CreateOutputMediator()
        dynamic_fields_helper = dynamic.DynamicFieldsHelper(output_mediator)

        event, event_data = containers_test_lib.CreateEventFromValues(
            self._TEST_EVENTS[0])
        zone_string = dynamic_fields_helper.GetFormattedField(
            event, event_data, None, 'zone')
        self.assertEqual(zone_string, 'UTC')
Ejemplo n.º 8
0
    def testFormatDateTime(self):
        """Tests the _FormatDateTime function."""
        output_mediator = self._CreateOutputMediator()
        dynamic_fields_helper = dynamic.DynamicFieldsHelper(output_mediator)

        event = TestEvent()
        date_time_string = dynamic_fields_helper._FormatDateTime(event)
        self.assertEqual(date_time_string, '2012-06-27T18:17:01+00:00')

        event.timestamp = -9223372036854775808
        date_time_string = dynamic_fields_helper._FormatDateTime(event)
        self.assertEqual(date_time_string, '0000-00-00T00:00:00')
Ejemplo n.º 9
0
    def testFormatTime(self):
        """Tests the _FormatTime function."""
        output_mediator = self._CreateOutputMediator()
        dynamic_fields_helper = dynamic.DynamicFieldsHelper(output_mediator)

        event = TestEvent()
        time_string = dynamic_fields_helper._FormatTime(event)
        self.assertEqual(time_string, '18:17:01')

        event.timestamp = -9223372036854775808
        time_string = dynamic_fields_helper._FormatTime(event)
        self.assertEqual(time_string, '--:--:--')
Ejemplo n.º 10
0
    def testFormatTimestampDescription(self):
        """Tests the _FormatTimestampDescription function."""
        output_mediator = self._CreateOutputMediator()
        dynamic_fields_helper = dynamic.DynamicFieldsHelper(output_mediator)

        event, event_data = containers_test_lib.CreateEventFromValues(
            self._TEST_EVENTS[0])
        timestamp_description_string = (
            dynamic_fields_helper._FormatTimestampDescription(
                event, event_data))
        self.assertEqual(timestamp_description_string,
                         'Metadata Modification Time')
Ejemplo n.º 11
0
    def testFormatTime(self):
        """Tests the _FormatTime function."""
        output_mediator = self._CreateOutputMediator()
        dynamic_fields_helper = dynamic.DynamicFieldsHelper(output_mediator)

        event, event_data = containers_test_lib.CreateEventFromValues(
            self._TEST_EVENTS[0])
        time_string = dynamic_fields_helper._FormatTime(event, event_data)
        self.assertEqual(time_string, '18:17:01')

        event.timestamp = -9223372036854775808
        time_string = dynamic_fields_helper._FormatTime(event, event_data)
        self.assertEqual(time_string, '--:--:--')
Ejemplo n.º 12
0
    def testFormatDate(self):
        """Tests the _FormatDate function."""
        output_mediator = self._CreateOutputMediator()
        dynamic_fields_helper = dynamic.DynamicFieldsHelper(output_mediator)

        event, event_data = containers_test_lib.CreateEventFromValues(
            self._TEST_EVENTS[0])
        date_string = dynamic_fields_helper._FormatDate(event, event_data)
        self.assertEqual(date_string, '2012-06-27')

        event.timestamp = -9223372036854775808
        date_string = dynamic_fields_helper._FormatDate(event, event_data)
        self.assertEqual(date_string, '0000-00-00')
Ejemplo n.º 13
0
    def testFormatTag(self):
        """Tests the _FormatTag function."""
        output_mediator = self._CreateOutputMediator()
        dynamic_fields_helper = dynamic.DynamicFieldsHelper(output_mediator)

        tag_string = dynamic_fields_helper._FormatTag(None)
        self.assertEqual(tag_string, '-')

        event_tag = events.EventTag()
        event_tag.AddLabel('one')
        event_tag.AddLabel('two')

        tag_string = dynamic_fields_helper._FormatTag(event_tag)
        self.assertEqual(tag_string, 'one two')
Ejemplo n.º 14
0
  def __init__(self, output_mediator):
    """Initializes an Excel Spreadsheet (XLSX) output module.

    Args:
      output_mediator (OutputMediator): output mediator.
    """
    super(XLSXOutputModule, self).__init__(output_mediator)
    self._column_widths = {}
    self._current_row = 0
    self._dynamic_fields_helper = dynamic.DynamicFieldsHelper(output_mediator)
    self._fields = self._DEFAULT_FIELDS
    self._filename = None
    self._sheet = None
    self._timestamp_format = self._DEFAULT_TIMESTAMP_FORMAT
    self._workbook = None
Ejemplo n.º 15
0
    def testFormatSource(self):
        """Tests the _FormatSource function."""
        formatters_manager.FormattersManager.RegisterFormatter(
            TestEventFormatter)

        output_mediator = self._CreateOutputMediator()
        dynamic_fields_helper = dynamic.DynamicFieldsHelper(output_mediator)

        event, event_data = containers_test_lib.CreateEventFromValues(
            self._TEST_EVENTS[0])
        source_string = dynamic_fields_helper._FormatSource(event, event_data)
        self.assertEqual(source_string, 'Syslog')

        formatters_manager.FormattersManager.DeregisterFormatter(
            TestEventFormatter)
Ejemplo n.º 16
0
    def testFormatMessageShort(self):
        """Tests the _FormatMessageShort function."""
        formatters_manager.FormattersManager.RegisterFormatter(
            TestEventFormatter)

        output_mediator = self._CreateOutputMediator()
        dynamic_fields_helper = dynamic.DynamicFieldsHelper(output_mediator)

        event = TestEvent()
        message_short_string = dynamic_fields_helper._FormatMessageShort(event)
        expected_message_short_string = (
            'Reporter <CRON> PID: 8442 (pam_unix(cron:session): session closed '
            'for user root)')
        self.assertEqual(message_short_string, expected_message_short_string)

        formatters_manager.FormattersManager.DeregisterFormatter(
            TestEventFormatter)
Ejemplo n.º 17
0
    def testFormatMessage(self):
        """Tests the _FormatMessage function."""
        formatters_manager.FormattersManager.RegisterFormatter(
            TestEventFormatter)

        output_mediator = self._CreateOutputMediator()
        dynamic_fields_helper = dynamic.DynamicFieldsHelper(output_mediator)

        event, event_data = containers_test_lib.CreateEventFromValues(
            self._TEST_EVENTS[0])
        message_string = dynamic_fields_helper._FormatMessage(
            event, event_data)
        expected_message_string = (
            'Reporter <CRON> PID: 8442 (pam_unix(cron:session): session closed '
            'for user root)')
        self.assertEqual(message_string, expected_message_string)

        formatters_manager.FormattersManager.DeregisterFormatter(
            TestEventFormatter)