94
94
Inventory::Build (bool noSoftware)
95
95
{
96
96
Logger::Log (LOG_INFO, " Building inventory..." );
97
+ std::string inventoryFormat = Configuration::Get ()->KeyValue (" format" );
98
+ if (inventoryFormat.empty ()) {
99
+ Logger::Log (LOG_WARNING, " No inventory format specified. Using lowest common denominator." );
100
+ }
97
101
try {
98
- // TODO: For glpi only
99
- tinyxml2::XMLElement* versionClient = fDocument ->NewElement (" VERSIONCLIENT" );
100
- versionClient->LinkEndChild (fDocument ->NewText (" 1.9.9" ));
101
- fContent ->LinkEndChild (versionClient);
102
+ if (inventoryFormat == " FORMAT_GLPI" ) {
103
+ tinyxml2::XMLElement* versionClient = fDocument ->NewElement (" VERSIONCLIENT" );
104
+ versionClient->LinkEndChild (fDocument ->NewText (" 1.9.9" ));
105
+ fContent ->LinkEndChild (versionClient);
106
+ }
102
107
_AddAccountInfo ();
103
108
_AddBIOSInfo ();
104
109
_AddOperatingSystemInfo ();
@@ -544,19 +549,75 @@ Inventory::_AddCPUsInfo()
544
549
tinyxml2::XMLElement* cpu = fDocument ->NewElement (" CPUS" );
545
550
fContent ->LinkEndChild (cpu);
546
551
547
- #if 0
548
- // OCSInventoryFormatOCS always reports "CPU Enabled" here
549
- // TODO: GLPI doesn't really like serial number and rejects the inventory
550
- tinyxml2::XMLElement* serial = fDocument->NewElement("SERIALNUMBER");
551
- std::string cpuSerial = cpuInfo.fields["serial"];
552
- if (cpuSerial.empty())
553
- cpuSerial = "CPU Enabled";
554
- if (cpuSerial == "None")
555
- cpuSerial = "";
556
- serial->LinkEndChild(
557
- fDocument->NewText(cpuSerial.c_str()));
558
- cpu->LinkEndChild(serial);
559
- #endif
552
+ // OCS Inventory
553
+ if (Configuration::Get ()->KeyValue (" format" ) == " FORMAT_OCS" ) {
554
+ // The official OCSInventory linux Agent always reports "CPU Enabled" here
555
+ tinyxml2::XMLElement* serial = fDocument ->NewElement (" SERIALNUMBER" );
556
+ std::string cpuSerial = cpuInfo.fields [" serial" ];
557
+ if (cpuSerial.empty ())
558
+ cpuSerial = " CPU Enabled" ;
559
+ if (cpuSerial == " None" )
560
+ cpuSerial = " " ;
561
+ serial->LinkEndChild (
562
+ fDocument ->NewText (cpuSerial.c_str ()));
563
+ cpu->LinkEndChild (serial);
564
+
565
+ tinyxml2::XMLElement* currentSpeed = fDocument ->NewElement (" CURRENT_SPEED" );
566
+ currentSpeed->LinkEndChild (
567
+ fDocument ->NewText (cpuInfo.fields [" current_speed" ].c_str ()));
568
+ cpu->LinkEndChild (currentSpeed);
569
+
570
+ tinyxml2::XMLElement* cores = fDocument ->NewElement (" CORES" );
571
+ cores->LinkEndChild (
572
+ fDocument ->NewText (cpuInfo.fields [" cores" ].c_str ()));
573
+ cpu->LinkEndChild (cores);
574
+ tinyxml2::XMLElement* arch = fDocument ->NewElement (" CPUARCH" );
575
+ arch->LinkEndChild (
576
+ fDocument ->NewText (gComponents [" OS" ].fields [" architecture" ].c_str ()));
577
+ cpu->LinkEndChild (arch);
578
+ tinyxml2::XMLElement* dataWidth = fDocument ->NewElement (" DATA_WIDTH" );
579
+ std::string dataWidthString = gComponents [" CPU" ].fields [" width" ];
580
+ if (dataWidthString.empty ()) {
581
+ // TODO: This is not completely correct:
582
+ // We could have a 64 bit capable CPU on a 32 bit OS.
583
+ if (gComponents [" OS" ].fields [" architecture" ] == " x86_64" )
584
+ dataWidthString = " 64" ;
585
+ else
586
+ dataWidthString = " 32" ;
587
+ }
588
+ dataWidth->LinkEndChild (
589
+ fDocument ->NewText (dataWidthString.c_str ()));
590
+ cpu->LinkEndChild (dataWidth);
591
+ // Not a copy/paste error: the fields are the same
592
+
593
+ tinyxml2::XMLElement* currentAddressWidth = fDocument ->NewElement (" CURRENT_ADDRESS_WIDTH" );
594
+ currentAddressWidth->LinkEndChild (
595
+ fDocument ->NewText (dataWidthString.c_str ()));
596
+ cpu->LinkEndChild (currentAddressWidth);
597
+
598
+ tinyxml2::XMLElement* cacheSize = fDocument ->NewElement (" L2CACHESIZE" );
599
+ cacheSize->LinkEndChild (
600
+ fDocument ->NewText (cpuInfo.fields [" cache_size" ].c_str ()));
601
+ cpu->LinkEndChild (cacheSize);
602
+
603
+ tinyxml2::XMLElement* logicalCpu = fDocument ->NewElement (" LOGICAL_CPUS" );
604
+ logicalCpu->LinkEndChild (
605
+ fDocument ->NewText (cpuInfo.fields [" logical_cpus" ].c_str ()));
606
+ cpu->LinkEndChild (logicalCpu);
607
+
608
+ tinyxml2::XMLElement* voltage = fDocument ->NewElement (" VOLTAGE" );
609
+ voltage->LinkEndChild (
610
+ fDocument ->NewText (cpuInfo.fields [" voltage" ].c_str ()));
611
+ cpu->LinkEndChild (voltage);
612
+
613
+ } else if (Configuration::Get ()->KeyValue (" format" ) == " FORMAT_GLPI" ) {
614
+ // GLPI
615
+ tinyxml2::XMLElement* cores = fDocument ->NewElement (" CORE" );
616
+ cores->LinkEndChild (
617
+ fDocument ->NewText (cpuInfo.fields [" cores" ].c_str ()));
618
+ cpu->LinkEndChild (cores);
619
+ }
620
+
560
621
tinyxml2::XMLElement* manufacturer = fDocument ->NewElement (" MANUFACTURER" );
561
622
cpu->LinkEndChild (manufacturer);
562
623
manufacturer->LinkEndChild (
@@ -566,12 +627,7 @@ Inventory::_AddCPUsInfo()
566
627
speed->LinkEndChild (
567
628
fDocument ->NewText (cpuInfo.fields [" speed" ].c_str ()));
568
629
cpu->LinkEndChild (speed);
569
- #if 0
570
- tinyxml2::XMLElement* currentSpeed = fDocument->NewElement("CURRENT_SPEED");
571
- currentSpeed->LinkEndChild(
572
- fDocument->NewText(cpuInfo.fields["current_speed"].c_str()));
573
- cpu->LinkEndChild(currentSpeed);
574
- #endif
630
+
575
631
tinyxml2::XMLElement* model = fDocument ->NewElement (" TYPE" );
576
632
model->LinkEndChild (
577
633
fDocument ->NewText (cpuInfo.fields [" type" ].c_str ()));
@@ -582,59 +638,6 @@ Inventory::_AddCPUsInfo()
582
638
name->LinkEndChild (
583
639
fDocument ->NewText (cpuInfo.fields [" type" ].c_str ()));
584
640
cpu->LinkEndChild (name);
585
- #if 0
586
- // TODO: GLPI wants "CORE" here
587
- tinyxml2::XMLElement* cores = fDocument->NewElement("CORES");
588
- cores->LinkEndChild(
589
- fDocument->NewText(cpuInfo.fields["cores"].c_str()));
590
- cpu->LinkEndChild(cores);
591
- #endif
592
- #if 0
593
- tinyxml2::XMLElement* arch = fDocument->NewElement("CPUARCH");
594
- arch->LinkEndChild(
595
- fDocument->NewText(gComponents["OS"].fields["architecture"].c_str()));
596
- cpu->LinkEndChild(arch);
597
- #endif
598
- #if 0
599
- tinyxml2::XMLElement* dataWidth = fDocument->NewElement("DATA_WIDTH");
600
- std::string dataWidthString = gComponents["CPU"].fields["width"];
601
- if (dataWidthString.empty()) {
602
- // TODO: This is not completely correct:
603
- // We could have a 64 bit capable CPU on a 32 bit OS.
604
- if (gComponents["OS"].fields["architecture"] == "x86_64")
605
- dataWidthString = "64";
606
- else
607
- dataWidthString = "32";
608
- }
609
- dataWidth->LinkEndChild(
610
- fDocument->NewText(dataWidthString.c_str()));
611
- cpu->LinkEndChild(dataWidth);
612
- // Not a copy/paste error: the fields are the same
613
-
614
- tinyxml2::XMLElement* currentAddressWidth = fDocument->NewElement("CURRENT_ADDRESS_WIDTH");
615
- currentAddressWidth->LinkEndChild(
616
- fDocument->NewText(dataWidthString.c_str()));
617
- cpu->LinkEndChild(currentAddressWidth);
618
- #endif
619
- #if 0
620
- tinyxml2::XMLElement* cacheSize = fDocument->NewElement("L2CACHESIZE");
621
- cacheSize->LinkEndChild(
622
- fDocument->NewText(cpuInfo.fields["cache_size"].c_str()));
623
- cpu->LinkEndChild(cacheSize);
624
- #endif
625
- #if 0
626
- tinyxml2::XMLElement* logicalCpu = fDocument->NewElement("LOGICAL_CPUS");
627
- logicalCpu->LinkEndChild(
628
- fDocument->NewText(cpuInfo.fields["logical_cpus"].c_str()));
629
- cpu->LinkEndChild(logicalCpu);
630
- #endif
631
- #if 0
632
- tinyxml2::XMLElement* voltage = fDocument->NewElement("VOLTAGE");
633
- voltage->LinkEndChild(
634
- fDocument->NewText(cpuInfo.fields["voltage"].c_str()));
635
- cpu->LinkEndChild(voltage);
636
- #endif
637
-
638
641
639
642
}
640
643
Logger::Log (LOG_DEBUG, " \t Added CPUs Info!" );
0 commit comments