def test_sparql_callback_associator_logical_disk(self): logging.critical("THIS IS DEPRECATED") callback_object = lib_wmi.WmiSparqlCallbackApi() grph = rdflib.Graph() iterator_objects = callback_object.CallbackAssociator( grph, result_class_name = "Win32_ComputerSystem", predicate_prefix = "WBEM", associator_key_name = "Win32_SystemDevices", subject_path = r'\\%s\root\cimv2:Win32_LogicalDisk.DeviceID="C:"' % CurrentMachine) list_objects = list(iterator_objects) self.assertTrue(len(list_objects) == 1) # Example: Not all values are displayed. # {rdflib.term.URIRef(u'http://primhillcomputers.com/survol#TotalPhysicalMemory'): rdflib.term.Literal(u'17099120640 B'), # rdflib.term.URIRef(u'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'): 'Win32_ComputerSystem', # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#Manufacturer'): rdflib.term.Literal(u'Hewlett-Packard'), # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#UserName'): rdflib.term.Literal(u'rchateau-HP\\\\rchateau'), # rdflib.term.URIRef(u'http://www.w3.org/2000/01/rdf-schema#seeAlso'): rdflib.term.Literal(u'WMI'), # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#CreationClassName'): rdflib.term.Literal(u'Win32_ComputerSystem'), # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#DNSHostName'): rdflib.term.Literal(u'rchateau-HP'), # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#Workgroup'): rdflib.term.Literal(u'WORKGROUP'), # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#Domain'): rdflib.term.Literal(u'WORKGROUP'), # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#Description'): rdflib.term.Literal(u'AT/AT COMPATIBLE'), # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#PrimaryOwnerName'): rdflib.term.Literal(u'rchateau'), # rdflib.term.URIRef(u'http://www.w3.org/2000/01/rdf-schema#isDefinedBy'): rdflib.term.Literal(u'WMI'), # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#Caption'): rdflib.term.Literal(u'RCHATEAU-HP'), # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#Name'): rdflib.term.Literal(u'RCHATEAU-HP'), for object_path, dict_key_values in list_objects: print(object_path) print(dict_key_values) self.assertTrue(GetElementAsString(dict_key_values, 'CreationClassName') == "Win32_ComputerSystem") # Problem on Travis: Name='PACKER-5D93E860', DNSHostName='packer-5d93e860-43ba-c2e7-85d2-3ea0696b8fc8' self.assertTrue(GetElementAsString(dict_key_values, 'Name').lower() == CurrentDomainWin32)
def test_sparql_callback_types(self): callback_object = lib_wmi.WmiSparqlCallbackApi() grph = rdflib.Graph() iterator_types = callback_object.CallbackTypes(grph, "see_also", {}) for object_path, dict_key_values in iterator_types: print(object_path) print(dict_key_values)
def Main(): lib_util.SetLoggingConfig(logging.ERROR) envSparql = lib_sparql.SparqlEnvironment() grph = lib_kbase.MakeGraph() sparql_query = envSparql.Query() lib_sparql.QueryToGraph(grph, sparql_query, lib_wmi.WmiSparqlCallbackApi()) envSparql.WriteTripleStoreAsString(grph)
def Main(): logging.critical("THIS IS DEPRECATED") lib_util.SetLoggingConfig(logging.ERROR) envSparql = lib_sparql.SparqlEnvironment() grph = rdflib.Graph() sparql_query = envSparql.Query() lib_sparql.QueryToGraph(grph, sparql_query, lib_wmi.WmiSparqlCallbackApi()) envSparql.WriteTripleStoreAsString(grph)
def test_sparql_callback_select(self): # TODO: Beware, this can be incredibly very slow depending on the properties. callback_object = lib_wmi.WmiSparqlCallbackApi() filtered_where_key_values = {"Handle": CurrentPid} grph = lib_kbase.MakeGraph() iterator_objects = callback_object.CallbackSelect( grph, "CIM_Process", "WBEM", filtered_where_key_values) list_objects = list(iterator_objects) for object_path, dict_key_values in list_objects: DEBUG(object_path) DEBUG(dict_key_values) print(object_path) print(dict_key_values) self.assertTrue(len(list_objects) == 1) # Example: Only some properties are displayed. # '\\RCHATEAU-HP\root\cimv2:Win32_Process.Handle="164944"' # '{rdflib.term.URIRef(u'http://primhillcomputers.com/survol#OtherTransferCount'): rdflib.term.Literal(u'733244'), # rdflib.term.URIRef(u'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'): rdflib.term.URIRef(u'http://primhillcomputers.com/survol#CIM_Process'), # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#QuotaNonPagedPoolUsage'): rdflib.term.Literal(u'18'), # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#ProcessId'): rdflib.term.Literal(u'164944'), # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#CSCreationClassName'): rdflib.term.Literal(u'Win32_ComputerSystem'), # rdflib.term.URIRef(u'http://www.w3.org/2000/01/rdf-schema#seeAlso'): rdflib.term.Literal(u'WMI'), # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#CreationClassName'): rdflib.term.Literal(u'Win32_Process'), # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#CSName'): rdflib.term.Literal(u'RCHATEAU-HP'), # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#OtherOperationCount'): rdflib.term.Literal(u'22068'), # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#CommandLine'): rdflib.term.Literal(u'C:\\\\Python27\\\\python.exe "C:\\\\Program Files\\\\JetBrains\\\\PyCharm Community Edition 2019.1.3\\\\helpers\\\\pycharm\\\\_jb_unittest_runner.py" --target test_lib_wmi.LibWmiTest.test_sparql_callback_select'), # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#Description'): rdflib.term.Literal(u'python.exe'), # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#OSCreationClassName'): rdflib.term.Literal(u'Win32_OperatingSystem'), # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#ExecutablePath'): rdflib.term.Literal(u'C:\\\\Python27\\\\python.exe'), # rdflib.term.URIRef(u'http://www.w3.org/2000/01/rdf-schema#isDefinedBy'): rdflib.term.Literal(u'WMI'), # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#Caption'): rdflib.term.Literal(u'python.exe'), # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#Name'): rdflib.term.Literal(u'python.exe')}" one_path, one_dict = list_objects[0] self.assertTrue( GetElementAsString(one_dict, 'Handle') == str(CurrentPid)) self.assertTrue( GetElementAsString(one_dict, 'ProcessId') == str(CurrentPid)) # Spelled "ParentProcessID" in WBEM. self.assertTrue( GetElementAsString(one_dict, 'ParentProcessId') == str( CurrentParentPid)) self.assertTrue( GetElementAsString(one_dict, 'OSCreationClassName') == 'Win32_OperatingSystem') self.assertTrue( GetElementAsString(one_dict, 'Caption') == 'python.exe')
def test_sparql_callback_associator_process(self): callback_object = lib_wmi.WmiSparqlCallbackApi() grph = lib_kbase.MakeGraph() iterator_objects = callback_object.CallbackAssociator( grph, result_class_name="CIM_DataFile", predicate_prefix="WBEM", associator_key_name="CIM_ProcessExecutable", subject_path=r'\\%s\root\cimv2:CIM_Process.Handle=%s' % (CurrentMachine, CurrentPid)) # Example: Only some properties are displayed. # { # rdflib.term.URIRef(u'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'): 'CIM_DataFile', # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#System'): rdflib.term.Literal(u'False'), # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#EightDotThreeFileName'): rdflib.term.Literal(u'c:\\\\windows\\\\system32\\\\ntdll.dll'), # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#Readable'): rdflib.term.Literal(u'True'), # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#Manufacturer'): rdflib.term.Literal(u'Microsoft Corporation'), # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#Hidden'): rdflib.term.Literal(u'False'), # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#CSCreationClassName'): rdflib.term.Literal(u'Win32_ComputerSystem'), # rdflib.term.URIRef(u'http://www.w3.org/2000/01/rdf-schema#seeAlso'): rdflib.term.Literal(u'WMI'), # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#FSCreationClassName'): rdflib.term.Literal(u'Win32_FileSystem'), # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#FileName'): rdflib.term.Literal(u'ntdll'), # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#CSName'): rdflib.term.Literal(u'RCHATEAU-HP'), # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#FSName'): rdflib.term.Literal(u'NTFS'), # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#Drive'): rdflib.term.Literal(u'c:'), # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#CreationClassName'): rdflib.term.Literal(u'CIM_LogicalFile'), # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#Description'): rdflib.term.Literal(u'c:\\\\windows\\\\system32\\\\ntdll.dll'), # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#FileType'): rdflib.term.Literal(u'Application Extension'), # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#Path'): rdflib.term.Literal(u'\\\\windows\\\\system32\\\\'), # rdflib.term.URIRef(u'http://www.w3.org/2000/01/rdf-schema#isDefinedBy'): rdflib.term.Literal(u'WMI'), # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#Caption'): rdflib.term.Literal(u'c:\\\\windows\\\\system32\\\\ntdll.dll'), # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#Name'): rdflib.term.Literal(u'c:\\\\windows\\\\system32\\\\ntdll.dll'), # rdflib.term.URIRef(u'http://primhillcomputers.com/survol#Extension'): rdflib.term.Literal(u'dll') # } found_kernel32_dll = False for object_path, dict_key_values in iterator_objects: self.assertEqual( GetElementAsString(dict_key_values, 'FSCreationClassName'), "Win32_FileSystem") self.assertEqual( GetElementAsString(dict_key_values, 'CreationClassName'), "CIM_LogicalFile") if not found_kernel32_dll: # Conversion to lower case because on Windows10 it is "KERNEL32.DLL". found_kernel32_dll = GetElementAsString( dict_key_values, 'Name').lower().endswith("kernel32.dll") self.assertTrue(found_kernel32_dll)
import lib_sparql import lib_wmi import lib_sparql_callback_survol import lib_export_ontology # For the moment, it just displays the content of the input to standard error, # so the SparQL protocol can be analysed. # See Experimental/Test_package_sparqlwrapper.py # http://timgolden.me.uk/python/downloads/wmi-0.6b.py lib_util.SetLoggingConfig(logging.DEBUG) prefix_to_callbacks = { "WMI": lib_wmi.WmiSparqlCallbackApi(), "survol": lib_sparql_callback_survol.SurvolSparqlCallbackApi(), } objectCallback = lib_sparql.SwitchCallbackApi(prefix_to_callbacks) # This is a SPARQL server which executes the query with WMI data. def Main(): lib_util.SetLoggingConfig(logging.ERROR) envSparql = lib_sparql.SparqlEnvironment() grph = lib_kbase.MakeGraph() sparql_query = envSparql.Query()