Beispiel #1
0
def GetClientInformation():
    return rdfvalue.ClientInformation(
        client_name=config_lib.CONFIG["Client.name"],
        client_description=config_lib.CONFIG["Client.description"],
        client_version=int(config_lib.CONFIG["Client.version_numeric"]),
        build_time=config_lib.CONFIG["Client.build_time"],
        labels=config_lib.CONFIG.Get("Client.labels", default=None))
 def GetClientInfo(self, _):
     return [
         rdfvalue.ClientInformation(
             client_name=config_lib.CONFIG["Client.name"],
             client_version=int(
                 config_lib.CONFIG["Client.version_numeric"]),
             build_time=config_lib.CONFIG["Client.build_time"],
             labels=["GRRLabel1", "Label2"],
         )
     ]
Beispiel #3
0
  def testGetMetadata(self):
    client_urn = rdfvalue.ClientURN("C.0000000000000000")
    test_lib.ClientFixture(client_urn, token=self.token)
    metadata = export.GetMetadata(client_urn, token=self.token)
    self.assertEqual(metadata.os, u"Windows")
    self.assertEqual(metadata.labels, u"")

    # Now set CLIENT_INFO with labels
    client_info = rdfvalue.ClientInformation(client_name="grr",
                                             labels=["a", "b"])
    client = aff4.FACTORY.Open(client_urn, mode="rw", token=self.token)
    client.Set(client.Schema.CLIENT_INFO(client_info))
    client.Flush()
    metadata = export.GetMetadata(client_urn, token=self.token)
    self.assertEqual(metadata.os, u"Windows")
    self.assertEqual(metadata.labels, u"a,b")
    def testAFF4CreateAndSet(self):
        """How long does it take to create and set properties."""

        client_info = rdfvalue.ClientInformation(
            client_name="GRR", client_description="Description")

        def CreateAFF4Object():
            """Blind write a VFSGRRClient with 1000 client info attributes."""
            fd = aff4.FACTORY.Create("C.1234567812345678",
                                     "VFSGRRClient",
                                     token=self.token)
            fd.Set(fd.Schema.HOSTNAME("Foobar"))
            for _ in range(1000):
                fd.AddAttribute(fd.Schema.CLIENT_INFO, client_info)

            fd.Close()

        # Time creation  into an empty data store.
        self.TimeIt(CreateAFF4Object, pre=data_store.DB.Clear)

        # Now we want to measure the time to read one of these object.
        data_store.DB.Clear()
        CreateAFF4Object()

        def ReadAFF4Object():
            fd = aff4.FACTORY.Open("C.1234567812345678",
                                   token=self.token,
                                   ignore_cache=True,
                                   age=aff4.ALL_TIMES)
            self.assertEqual(fd.Get(fd.Schema.HOSTNAME), "Foobar")

        self.TimeIt(ReadAFF4Object, name="Read attribute from AFF4Object")

        def ReadVersionedAFF4Attribute():
            fd = aff4.FACTORY.Open("C.1234567812345678",
                                   token=self.token,
                                   ignore_cache=True,
                                   age=aff4.ALL_TIMES)
            for x in fd.GetValuesForAttribute(fd.Schema.CLIENT_INFO):
                self.assertEqual(x.client_name, "GRR")

        self.TimeIt(ReadVersionedAFF4Attribute,
                    name="Read heavily versioned Attributes")

        def ReadSomeVersionedAFF4Attribute():
            fd = aff4.FACTORY.Open("C.1234567812345678",
                                   token=self.token,
                                   ignore_cache=True,
                                   age=aff4.ALL_TIMES)

            # Only read the top 5 attributes.
            for i, x in enumerate(
                    fd.GetValuesForAttribute(fd.Schema.CLIENT_INFO)):
                self.assertEqual(x.client_name, "GRR")
                if i > 50:
                    break

        self.TimeIt(ReadSomeVersionedAFF4Attribute,
                    name="Read few versioned Attributes")

        # Using Get() on a multi versioned object should only parse one value.
        def ReadAVersionedAFF4Attribute():
            fd = aff4.FACTORY.Open("C.1234567812345678",
                                   token=self.token,
                                   ignore_cache=True,
                                   age=aff4.ALL_TIMES)

            x = fd.Get(fd.Schema.CLIENT_INFO)
            self.assertEqual(x.client_name, "GRR")

        self.TimeIt(ReadAVersionedAFF4Attribute,
                    name="Read one versioned Attributes")