Subversion Repositories computer_asset_manager_v1

Rev

Rev 99 | Rev 102 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 99 Rev 100
Line 1... Line 1...
1
<?php
1
<?php
2
 
2
 
3
/*
3
   /*
4
 * Trims a value, then compares it to several 'null' possibilities
4
    * dmidecode2array.php
-
 
5
    * 
5
 * if it is a null, returns empty string, otherwise returns value
6
    * Set of routines which convert the output of dmidecode into an array containing key/value pairs.
6
 */
7
    *
7
function cleanUpDMIValue( $value ) {
8
    * Use this by including the file in your script, load the output of a dmidecode run into an array of lines, then call
8
   $value = trim( $value );
9
    * $array = dmidecode2array( $contentsOfFile ).
-
 
10
    * Sample code to read a file name from ARGV, process the file and dump the resulting array using print_r shown at
9
   switch (strtolower( $value )) {
11
    * bottom of this file, commented out.
10
      case 'unknown':
12
    * 
11
      case 'unspecified' :
13
    * Copyright (c) 2020 by the Daily Data, Inc. All rights reserved. Redistribution and use in source and binary forms, with or
12
      case 'not available':
14
    * without modification, are permitted provided that the following conditions are met:
-
 
15
    *     Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
-
 
16
    *     Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
13
      case 'to be filled by o.e.m.':
17
    *        disclaimer in the documentation and/or other materials provided with the distribution.
-
 
18
    *     Neither the name of the nor the names of its contributors may be used to endorse or promote products derived from this
14
      case 'not specified': return '';
19
    *       software without specific prior written permission.
-
 
20
    *
-
 
21
    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
-
 
22
    * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
-
 
23
    * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-
 
24
    * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-
 
25
    * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-
 
26
    * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
   }
27
    *
-
 
28
    * 20200113 rodo@dailydata.net v0.1
16
   return $value;
29
    * Initial build
-
 
30
    * 
17
}
31
    */
18
 
32
 
19
/*
-
 
20
 * Read value from array of hash, return array of "$outputKey\tvalue" for each entry found
-
 
21
 * If nothing found, returns empty array
-
 
22
 * if $unique is true, returns first non-empty value found
-
 
23
 * if $outputKey is not defined, uses $key
-
 
24
 */
-
 
25
function getDMIInformation( $data, $type, $key, $outputKey = '', $unique = true ) {
-
 
26
   $return = array();
-
 
27
   foreach ( $data[$type] as $handle ) {
-
 
28
      if ( isset( $handle[$key]) ) {
-
 
29
         $a = cleanUpDMIValue( $handle[$key] );
-
 
30
         if ( $a ) {
-
 
31
            $return[] = ( $outputKey ? $outputKey : $key ) . "\t" . $a;
-
 
32
            if ( $unique ) {
-
 
33
               return $return;
-
 
34
            }
-
 
35
         }
-
 
36
      }
-
 
37
   }
-
 
38
   return $return;
-
 
39
}
-
 
40
 
33
 
41
/*
-
 
42
 * adds $value to array
-
 
43
 * if $value is scalar, simply adds it
-
 
44
 * if $value is array, adds every row
-
 
45
 * returns modified array
-
 
46
 */
-
 
47
function addData( $array, $value ) {
-
 
48
   if ( $value ) {
-
 
49
      switch (gettype( $value ) ) {
-
 
50
         case 'array' : foreach ( $value as $thisVal ) {
-
 
51
                           $array[] = $thisVal;
-
 
52
                        }
-
 
53
                        break;
-
 
54
         case 'boolean' :
-
 
55
         case 'integer' :
-
 
56
         case 'double'  :
-
 
57
         case 'string'  : $array[] = $value;
-
 
58
      } // switch
-
 
59
   }
-
 
60
   return $array;
-
 
61
} //addData
-
 
62
 
34
 
63
/*
35
   /*
64
 * Function will take an array of lines representing the output of a dmidecode file
-
 
65
 * and pick and choose the values we want to put into CAMP attributes.
36
    * Trims a value, then compares it to several 'null' possibilities
66
 * It will return an array of key/value pairs to be added into the attributes table
37
    * if it is a null, returns empty string, otherwise returns value
67
 *
-
 
68
 * NOTE: this is a summary of values we decided to store. dmidecode files have a lot of
-
 
69
 * additional information we chose not to include
-
 
70
 * 
-
 
71
 */
38
    */
72
 
-
 
73
function dmidecode2array( $contents ) {
39
   function cleanUpDMIValue( $value ) {
74
 
-
 
75
// allows us to group the dmi types by function. not implemented
-
 
76
$dmiGroups = array(
-
 
77
      "bios" => "0,13",
-
 
78
      "system" => "1,12,15,23,32",
-
 
79
      "baseboard" => "2,10,41",
-
 
80
      "chassis" => "3",
-
 
81
      "processor" => "4",
-
 
82
      "memory" => "5,6,16,17",
-
 
83
      "cache" => "7",
-
 
84
      "connector" => "8",
-
 
85
      "slot" => "9"
-
 
86
);
-
 
87
 
-
 
88
// This contains the standard DMI types, ie no OEM stuff. For reference, not used in code
-
 
89
 
-
 
90
$standardDMITypes = array( 
-
 
91
      "0" => "BIOS",
-
 
92
      "1" => "System",
-
 
93
      "2" => "Baseboard",
-
 
94
      "3" => "Chassis",
-
 
95
      "4" => "Processor",
-
 
96
      "5" => "Memory Controller",
-
 
97
      "6" => "Memory Module",
40
      $value = trim( $value );
98
      "7" => "Cache",
-
 
99
      "8" => "Port Connector",
-
 
100
      "9" => "System Slots",
-
 
101
      "10" => "On Board Devices",
41
      switch (strtolower( $value )) {
102
      "11" => "OEM Strings",
42
         case 'unknown':
103
      "12" => "System Configuration Options",
-
 
104
      "13" => "BIOS Language",
-
 
105
      "14" => "Group Associations",
-
 
106
      "15" => "System Event Log",
-
 
107
      "16" => "Physical Memory Array",
-
 
108
      "17" => "Memory Device",
-
 
109
      "18" => "32-bit Memory Error",
-
 
110
      "19" => "Memory Array Mapped Address",
-
 
111
      "20" => "Memory Device Mapped Address",
-
 
112
      "21" => "Built-in Pointing Device",
-
 
113
      "22" => "Portable Battery",
-
 
114
      "23" => "System Reset",
43
         case 'unspecified' :
115
      "24" => "Hardware Security",
-
 
116
      "25" => "System Power Controls",
-
 
117
      "26" => "Voltage Probe",
44
         case 'not available':
118
      "27" => "Cooling Device",
-
 
119
      "28" => "Temperature Probe",
-
 
120
      "29" => "Electrical Current Probe",
-
 
121
      "30" => "Out-of-band Remote Access",
-
 
122
      "31" => "Boot Integrity Services",
-
 
123
      "32" => "System Boot",
-
 
124
      "33" => "64-bit Memory Error",
-
 
125
      "34" => "Management Device",
-
 
126
      "35" => "Management Device Component",
-
 
127
      "36" => "Management Device Threshold Data",
-
 
128
      "37" => "Memory Channel",
-
 
129
      "38" => "IPMI Device",
-
 
130
      "39" => "Power Supply",
-
 
131
      "40" => "Additional Information",
-
 
132
      "41" => "Onboard Devices Extended Information",
-
 
133
      "42" => "Management Controller Host Interface"
-
 
134
);
-
 
135
   
-
 
136
   // verify this is something we can work with, First line should be the version of dmidecode found
-
 
137
   if ( preg_match('/dmidecode ([0-9.]+)/', $contents[0], $results) ) {
-
 
138
      $dmidecodeVersion = $results[1];
-
 
139
   } else {
-
 
140
      return "Not a valid dmidecode file";
-
 
141
   }
-
 
142
   // first, let's parse it into a hash
-
 
143
   $currentHandle = '';
-
 
144
   $currentType;
-
 
145
   $data = array();
-
 
146
   for ( $i = 0; $i < count($contents); $i++ ) {
-
 
147
      if ( preg_match('/^Handle ([0-9a-zx]+).*DMI type[^0-9]*(\d+),/i', $contents[$i], $outputArray) ) {
-
 
148
         //print "matched\n"; print_r($outputArray); die;
-
 
149
         $currentType = $outputArray[2];
45
         case 'to be filled by o.e.m.':
150
         $currentHandle = $outputArray[1];
-
 
151
         if ( isset( $standardDMITypes[$currentType] ) || array_key_exists( $currentType,$standardDMITypes ) ) {
-
 
152
            $name = $contents[$i+1];
-
 
153
            $data[$currentType][$currentHandle]['name'] = $name;
-
 
154
            $i += 2; // skip the line with the name, and go to the next line
-
 
155
         } else {
-
 
156
            $currentType = $currentHandle = '';
46
         case 'not specified': return '';
157
         }
-
 
158
      }
-
 
159
      if ( $currentHandle &&  preg_match('/^\s+(.*):\s+(.*)$/i', $contents[$i], $outputArray) ) {
-
 
160
         $data[$currentType][$currentHandle][$outputArray[1]] = $outputArray[2];
-
 
161
      }
47
      }
-
 
48
      return $value;
162
   }
49
   }
163
   # well, we have at least one entry, so let's go
-
 
164
   $return = array();
-
 
165
   // manufacturer info
-
 
166
   $return = addData( $return, getDMIInformation( $data, '1','Manufacturer' ) );
-
 
167
   $return = addData( $return, getDMIInformation( $data, '1','Product Name', 'Model' ) );
-
 
168
   $return = addData( $return, getDMIInformation( $data, '1','Serial Number' ) );
-
 
169
   $return = addData( $return, getDMIInformation( $data, '1','UUID' ) );
-
 
170
   // physical machine
-
 
171
   $return = addData( $return, getDMIInformation( $data, '3','Type', 'Enclosure Type' ) );
-
 
172
   $return = addData( $return, getDMIInformation( $data, '3','Asset Tag', 'Enclosure Asset Tag' ) );
-
 
173
   $return = addData( $return, getDMIInformation( $data, '3','Height', 'Enclosure Height' ) );
-
 
174
 
-
 
175
   // firmware version
-
 
176
   $return = addData( $return, getDMIInformation( $data, '0','Vendor', 'Firmware Vendor' ) );
-
 
177
   $return = addData( $return, getDMIInformation( $data, '0','Release Date', 'Firmware Release' ) );
-
 
178
   $return = addData( $return, getDMIInformation( $data, '0','Version', 'Firmware Version' ) );
-
 
179
   $return = addData( $return, getDMIInformation( $data, '0','Firmware Revision', 'Firmware Revision' ) );
-
 
180
   // processor information. NOTE: assumes all sockets populated and all processors the saem
-
 
181
   if ( isset( $data['4'] ) ) // count the number of sockets
-
 
182
      $return[] = "CPU Count\t" . count( $data['4'] );
-
 
183
   $return = addData( $return, getDMIInformation( $data, '4','Family', 'CPU Family' ) );
-
 
184
   $return = addData( $return, getDMIInformation( $data, '4','Manufacturer', 'CPU Manufacturer' ) );
-
 
185
   $return = addData( $return, getDMIInformation( $data, '4','Version', 'CPU Version' ) );
-
 
186
   $return = addData( $return, getDMIInformation( $data, '4','Current Speed', 'CPU Speed' ) );
-
 
187
   $return = addData( $return, getDMIInformation( $data, '4','Core Count', 'CPU Cores (ea)' ) );
-
 
188
   $return = addData( $return, getDMIInformation( $data, '4','Thread Count', 'CPU Threads (ea)' ) );
-
 
189
 
50
 
190
   /*
51
   /*
191
    * memory information. We want details on each slot for this, so we have to go through each entry, one at a time.
52
    * Read value from array of hash, return array of "$outputKey\tvalue" for each entry found
192
    * For readability, we also want to take several values and turn them into one human
53
    * If nothing found, returns empty array
193
    * readable string for each socket. So, we go through each entry in the memory socket, determine if it is populated
54
    * if $unique is true, returns first non-empty value found
194
    * then concat it together for a pretty output
55
    * if $outputKey is not defined, uses $key
195
    */
56
    */
196
   
-
 
197
   if ( isset( $data['17'] ) ) {
-
 
198
      $return[] = "Memory Slots\t" . count( $data['17'] );
-
 
199
      $totalRAM = 0; // we'll accumulate the total size as we find slots populated
57
   function getDMIInformation( $data, $type, $key, $outputKey = '', $unique = true ) {
200
      foreach ( $data['17'] as $entry ) { // type 17 has one entry for every DIMM slot
-
 
201
         $mem = array(); // fill this up with the values we want to turn into a string, then we'll implode it into the string
-
 
202
         $mem[] = trim($entry['Locator'] ? $entry['Locator'] : ($entry['Bank Locator'] ? $entry['Bank Locator'] : '' ));
-
 
203
         if ( $entry['Size'] == 'No Module Installed' ) {
-
 
204
            $mem[] = 'Unpopulated';
-
 
205
         } else {
58
      $return = array();
206
            $mem[] = trim($entry['Size']); // size can be kilo, meg, gig, tera, so convert it to mega
-
 
207
            if ( preg_match('/(\d+)\s+(GB|MB|TB|kb)/i', $entry['Size'] , $outputArray) ) {
-
 
208
               switch ( strtolower( $outputArray[2] ) ) {
59
      foreach ( $data[$type] as $handle ) {
209
                  case 'gb' :
60
         if ( isset( $handle[$key]) ) {
210
                           $outputArray[1] *= 1024;
61
            $a = cleanUpDMIValue( $handle[$key] );
211
                           break;
-
 
212
                  case 'tb' : 
62
            if ( $a ) {
213
                           $outputArray[1] *= 1024 * 1024;
63
               $return[] = ( $outputKey ? $outputKey : $key ) . "\t" . $a;
214
                           break;
-
 
215
                  case 'kb' : 
64
               if ( $unique ) {
216
                           $outputArray[1] /= 1024;
-
 
217
                           break;
65
                  return $return;
218
               }
66
               }
219
               $totalRAM += $outputArray[1];
-
 
220
            }
67
            }
221
            $mem[] = trim($entry['Form Factor']);
-
 
222
            $mem[] = trim($entry['Type']);
-
 
223
            $mem[] = trim($entry['Data Width']);
-
 
224
            if ( isset( $entry['Configured Clock Speed']) && isset($entry['Speed']) && cleanUpDMIValue($entry['Configured Clock Speed']) && cleanUpDMIValue($entry['Speed']) )
-
 
225
               $mem[] = cleanUpDMIValue($entry['Configured Clock Speed'] . '/' . cleanUpDMIValue($entry['Speed']) );
-
 
226
            if ( isset($entry['Manufacturer']) && cleanUpDMIValue($entry['Manufacturer']) )
-
 
227
               $mem[] = cleanUpDMIValue($entry['Manufacturer']);
-
 
228
            if ( isset($entry['Part Number']) && cleanUpDMIValue( $entry['Part Number'] ) )
-
 
229
               $mem[] = 'p/n ' . cleanUpDMIValue($entry['Part Number']);
-
 
230
            if ( isset($entry['Serial Number']) && trim($entry['Serial Number']) != 'Not Specified' )
-
 
231
               $mem[] = 's/n ' . cleanUpDMIValue($entry['Serial Number']);
-
 
232
         }
68
         }
233
         $return[] = "Memory\t" . implode( ', ', $mem );
-
 
234
      }
69
      }
235
      $return[] = "Memory Total\t$totalRAM MB";
70
      return $return;
236
   }
71
   }
237
 
72
 
238
   /*
73
   /*
-
 
74
    * adds $value to array
-
 
75
    * if $value is scalar, simply adds it
-
 
76
    * if $value is array, adds every row
-
 
77
    * returns modified array
-
 
78
    *
239
    * power supplies. Most workstations will not even have an entry here, but for servers we will have details on each individual
79
    * Can be done more efficiently with some PHP built-ins, but I forgot how.
-
 
80
    */
-
 
81
   function mergeArrays( $array, $value ) {
-
 
82
      if ( $value ) {
-
 
83
         switch (gettype( $value ) ) {
240
    * power supply, including the part number, serial number, etc..., so like memory, we want a detailed listing with a human
84
            case 'array' : foreach ( $value as $thisVal ) {
-
 
85
                              $array[] = $thisVal;
-
 
86
                           }
-
 
87
                           break;
-
 
88
            case 'boolean' :
-
 
89
            case 'integer' :
-
 
90
            case 'double'  :
241
    * readable string for each psu
91
            case 'string'  : $array[] = $value;
-
 
92
         } // switch
-
 
93
      }
-
 
94
      return $array;
-
 
95
   } //mergeArrays
-
 
96
 
-
 
97
 
-
 
98
   /*
-
 
99
    * Function will take an array of lines representing the output of a dmidecode file
-
 
100
    * and pick and choose the values we want to put into CAMP attributes.
-
 
101
    * It will return an array of key/value pairs to be added into the attributes table
-
 
102
    *
-
 
103
    * NOTE: this is a summary of values we decided to store. dmidecode files have a lot of
-
 
104
    * additional information we chose not to include, but they can be added by simply modifying the 
-
 
105
    * 
242
    */
106
    */
-
 
107
 
-
 
108
   function dmidecode2array( $contents ) {
-
 
109
 
-
 
110
   // allows us to group the dmi types by function. not implemented
-
 
111
   $dmiGroups = array(
-
 
112
         "bios" => "0,13",
-
 
113
         "system" => "1,12,15,23,32",
243
   if ( isset( $data['39'] ) ) {
114
         "baseboard" => "2,10,41",
-
 
115
         "chassis" => "3",
-
 
116
         "processor" => "4",
-
 
117
         "memory" => "5,6,16,17",
-
 
118
         "cache" => "7",
-
 
119
         "connector" => "8",
-
 
120
         "slot" => "9"
-
 
121
   );
-
 
122
 
-
 
123
   // This contains the standard DMI types, ie no OEM stuff. For reference, not used in code
-
 
124
 
-
 
125
   $standardDMITypes = array( 
-
 
126
         "0" => "BIOS",
-
 
127
         "1" => "System",
-
 
128
         "2" => "Baseboard",
-
 
129
         "3" => "Chassis",
-
 
130
         "4" => "Processor",
-
 
131
         "5" => "Memory Controller",
-
 
132
         "6" => "Memory Module",
-
 
133
         "7" => "Cache",
-
 
134
         "8" => "Port Connector",
-
 
135
         "9" => "System Slots",
-
 
136
         "10" => "On Board Devices",
-
 
137
         "11" => "OEM Strings",
244
      $return[] = "Power Supply Count\t" . count( $data['39'] );
138
         "12" => "System Configuration Options",
-
 
139
         "13" => "BIOS Language",
-
 
140
         "14" => "Group Associations",
-
 
141
         "15" => "System Event Log",
-
 
142
         "16" => "Physical Memory Array",
-
 
143
         "17" => "Memory Device",
-
 
144
         "18" => "32-bit Memory Error",
-
 
145
         "19" => "Memory Array Mapped Address",
-
 
146
         "20" => "Memory Device Mapped Address",
-
 
147
         "21" => "Built-in Pointing Device",
-
 
148
         "22" => "Portable Battery",
-
 
149
         "23" => "System Reset",
-
 
150
         "24" => "Hardware Security",
-
 
151
         "25" => "System Power Controls",
-
 
152
         "26" => "Voltage Probe",
-
 
153
         "27" => "Cooling Device",
-
 
154
         "28" => "Temperature Probe",
245
      foreach ( $data['39'] as $entry ) {
155
         "29" => "Electrical Current Probe",
-
 
156
         "30" => "Out-of-band Remote Access",
-
 
157
         "31" => "Boot Integrity Services",
-
 
158
         "32" => "System Boot",
-
 
159
         "33" => "64-bit Memory Error",
-
 
160
         "34" => "Management Device",
-
 
161
         "35" => "Management Device Component",
-
 
162
         "36" => "Management Device Threshold Data",
-
 
163
         "37" => "Memory Channel",
-
 
164
         "38" => "IPMI Device",
-
 
165
         "39" => "Power Supply",
-
 
166
         "40" => "Additional Information",
-
 
167
         "41" => "Onboard Devices Extended Information",
-
 
168
         "42" => "Management Controller Host Interface"
-
 
169
   );
-
 
170
      
-
 
171
      // verify this is something we can work with, First line should be the version of dmidecode found
246
         if ( preg_match('/^Present/i', $entry['Status'] ) ) {
172
      if ( preg_match('/dmidecode ([0-9.]+)/', $contents[0], $results) ) {
-
 
173
         $dmidecodeVersion = $results[1];
-
 
174
      } else {
-
 
175
         return "Not a valid dmidecode file";
-
 
176
      }
-
 
177
      // first, let's parse it into a hash
-
 
178
      $currentHandle = '';
-
 
179
      $currentType;
247
            $psu = array();
180
      $data = array();
-
 
181
      for ( $i = 0; $i < count($contents); $i++ ) {
-
 
182
         if ( preg_match('/^Handle ([0-9a-zx]+).*DMI type[^0-9]*(\d+),/i', $contents[$i], $outputArray) ) {
-
 
183
            //print "matched\n"; print_r($outputArray); die;
248
            $psu[] = trim($entry['Name']);
184
            $currentType = $outputArray[2];
249
            $psu[] = trim($entry['Max Power Capacity']);
185
            $currentHandle = $outputArray[1];
-
 
186
            if ( isset( $standardDMITypes[$currentType] ) || array_key_exists( $currentType,$standardDMITypes ) ) {
250
            $psu[] = trim($entry['Manufacturer']);
187
               $name = $contents[$i+1];
251
            $psu[] = 'p/n ' . trim($entry['Model Part Number']);
188
               $data[$currentType][$currentHandle]['name'] = $name;
-
 
189
               $i += 2; // skip the line with the name, and go to the next line
-
 
190
            } else {
252
            $psu[] = 's/n ' . trim($entry['Serial Number']);
191
               $currentType = $currentHandle = '';
-
 
192
            }
-
 
193
         }
-
 
194
         if ( $currentHandle &&  preg_match('/^\s+(.*):\s+(.*)$/i', $contents[$i], $outputArray) ) {
253
            $return[] = "Power Supply\t" . implode( ', ', $psu );
195
            $data[$currentType][$currentHandle][$outputArray[1]] = $outputArray[2];
254
         }
196
         }
255
      }
197
      }
-
 
198
      # well, we have at least one entry, so let's go
-
 
199
      $return = array();
-
 
200
 
-
 
201
      /*
-
 
202
       * Grab the information we want from the file. Note tht we are renaming some of the fields from the dmidecode output
-
 
203
       * to match the keyfields used by our system (4th parameter in getDMIInformation).
-
 
204
       *
-
 
205
       * First, we'll get the easy stuff; stuff which only has one value we care about.
-
 
206
       * 
-
 
207
       */
-
 
208
      // manufacturer info
-
 
209
      $return = mergeArrays( $return, getDMIInformation( $data, '1','Manufacturer' ) );
-
 
210
      $return = mergeArrays( $return, getDMIInformation( $data, '1','Product Name', 'Model' ) );
-
 
211
      $return = mergeArrays( $return, getDMIInformation( $data, '1','Serial Number' ) );
-
 
212
      $return = mergeArrays( $return, getDMIInformation( $data, '1','UUID' ) );
-
 
213
      // physical machine
-
 
214
      $return = mergeArrays( $return, getDMIInformation( $data, '3','Type', 'Enclosure Type' ) );
-
 
215
      $return = mergeArrays( $return, getDMIInformation( $data, '3','Asset Tag', 'Enclosure Asset Tag' ) );
-
 
216
      $return = mergeArrays( $return, getDMIInformation( $data, '3','Height', 'Enclosure Height' ) );
-
 
217
      // firmware version
-
 
218
      $return = mergeArrays( $return, getDMIInformation( $data, '0','Vendor', 'Firmware Vendor' ) );
-
 
219
      $return = mergeArrays( $return, getDMIInformation( $data, '0','Release Date', 'Firmware Release' ) );
-
 
220
      $return = mergeArrays( $return, getDMIInformation( $data, '0','Version', 'Firmware Version' ) );
-
 
221
      $return = mergeArrays( $return, getDMIInformation( $data, '0','Firmware Revision', 'Firmware Revision' ) );
-
 
222
      // processor information. NOTE: assumes all sockets populated and all processors the same. If this is not the case
-
 
223
      // we will need to modify the following to dump each individual socket, similar to the meory information below.
-
 
224
      if ( isset( $data['4'] ) ) // count the number of sockets
-
 
225
         $return[] = "CPU Count\t" . count( $data['4'] );
-
 
226
      $return = mergeArrays( $return, getDMIInformation( $data, '4','Family', 'CPU Family' ) );
-
 
227
      $return = mergeArrays( $return, getDMIInformation( $data, '4','Manufacturer', 'CPU Manufacturer' ) );
-
 
228
      $return = mergeArrays( $return, getDMIInformation( $data, '4','Version', 'CPU Version' ) );
-
 
229
      $return = mergeArrays( $return, getDMIInformation( $data, '4','Current Speed', 'CPU Speed' ) );
-
 
230
      $return = mergeArrays( $return, getDMIInformation( $data, '4','Core Count', 'CPU Cores (ea)' ) );
-
 
231
      $return = mergeArrays( $return, getDMIInformation( $data, '4','Thread Count', 'CPU Threads (ea)' ) );
-
 
232
 
-
 
233
      /*
-
 
234
       * memory information. We want details on each slot for this, so we have to go through each entry, one at a time.
-
 
235
       * For readability, we also want to take several values and turn them into one human
-
 
236
       * readable string for each socket. So, we go through each entry in the memory socket, determine if it is populated
-
 
237
       * then concat it together for a pretty output
-
 
238
       */
-
 
239
      
-
 
240
      if ( isset( $data['17'] ) ) {
-
 
241
         $return[] = "Memory Slots\t" . count( $data['17'] );
-
 
242
         $totalRAM = 0; // we'll accumulate the total size as we find slots populated
-
 
243
         foreach ( $data['17'] as $entry ) { // type 17 has one entry for every DIMM slot
-
 
244
            $mem = array(); // fill this up with the values we want to turn into a string, then we'll implode it into the string
-
 
245
            $mem[] = trim($entry['Locator'] ? $entry['Locator'] : ($entry['Bank Locator'] ? $entry['Bank Locator'] : '' ));
-
 
246
            if ( $entry['Size'] == 'No Module Installed' ) {
-
 
247
               $mem[] = 'Unpopulated';
-
 
248
            } else {
-
 
249
               $mem[] = trim($entry['Size']); // size can be kilo, meg, gig, tera, so convert it to mega
-
 
250
               if ( preg_match('/(\d+)\s+(GB|MB|TB|kb)/i', $entry['Size'] , $outputArray) ) {
-
 
251
                  switch ( strtolower( $outputArray[2] ) ) {
-
 
252
                     case 'gb' :
-
 
253
                              $outputArray[1] *= 1024;
-
 
254
                              break;
-
 
255
                     case 'tb' : 
-
 
256
                              $outputArray[1] *= 1024 * 1024;
-
 
257
                              break;
-
 
258
                     case 'kb' : 
-
 
259
                              $outputArray[1] /= 1024;
-
 
260
                              break;
-
 
261
                  }
-
 
262
                  $totalRAM += $outputArray[1];
-
 
263
               }
-
 
264
               $mem[] = trim($entry['Form Factor']);
-
 
265
               $mem[] = trim($entry['Type']);
-
 
266
               $mem[] = trim($entry['Data Width']);
-
 
267
               if ( isset( $entry['Configured Clock Speed']) && isset($entry['Speed']) && cleanUpDMIValue($entry['Configured Clock Speed']) && cleanUpDMIValue($entry['Speed']) )
-
 
268
                  $mem[] = cleanUpDMIValue($entry['Configured Clock Speed'] . '/' . cleanUpDMIValue($entry['Speed']) );
-
 
269
               if ( isset($entry['Manufacturer']) && cleanUpDMIValue($entry['Manufacturer']) )
-
 
270
                  $mem[] = cleanUpDMIValue($entry['Manufacturer']);
-
 
271
               if ( isset($entry['Part Number']) && cleanUpDMIValue( $entry['Part Number'] ) )
-
 
272
                  $mem[] = 'p/n ' . cleanUpDMIValue($entry['Part Number']);
-
 
273
               if ( isset($entry['Serial Number']) && trim($entry['Serial Number']) != 'Not Specified' )
-
 
274
                  $mem[] = 's/n ' . cleanUpDMIValue($entry['Serial Number']);
-
 
275
            }
-
 
276
            $return[] = "Memory\t" . implode( ', ', $mem );
-
 
277
         }
-
 
278
         $return[] = "Memory Total\t$totalRAM MB";
-
 
279
      }
-
 
280
 
-
 
281
      /*
-
 
282
       * power supplies. Most workstations will not even have an entry here, but for servers we will have details on each individual
-
 
283
       * power supply, including the part number, serial number, etc..., so like memory, we want a detailed listing with a human
-
 
284
       * readable string for each psu
-
 
285
       */
-
 
286
      if ( isset( $data['39'] ) ) {
-
 
287
         $return[] = "Power Supply Count\t" . count( $data['39'] );
-
 
288
         foreach ( $data['39'] as $entry ) {
-
 
289
            if ( preg_match('/^Present/i', $entry['Status'] ) ) {
-
 
290
               $psu = array();
-
 
291
               $psu[] = trim($entry['Name']);
-
 
292
               $psu[] = trim($entry['Max Power Capacity']);
-
 
293
               $psu[] = trim($entry['Manufacturer']);
-
 
294
               $psu[] = 'p/n ' . trim($entry['Model Part Number']);
-
 
295
               $psu[] = 's/n ' . trim($entry['Serial Number']);
-
 
296
               $return[] = "Power Supply\t" . implode( ', ', $psu );
-
 
297
            }
-
 
298
         }
-
 
299
      }
-
 
300
      return array( $return );
-
 
301
   }  // dmidecode2array
-
 
302
 
-
 
303
   /*
-
 
304
    * Test code for dmidecode input
-
 
305
    * call from cli as
-
 
306
    * php dmidecode2array FILENAME
-
 
307
    * the array will be dumped to STDOUT by print_r
-
 
308
    * 
-
 
309
    */
-
 
310
   /* remove this line for testing
-
 
311
 
-
 
312
   $filename = $argv[1]; // get first parameter from cli
-
 
313
   if ( $filename ) {
-
 
314
      // slurp file into array, ignore empty lines and remove line endings
-
 
315
      $contents = file( $filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
-
 
316
      // $out will contain the key/value pairs
-
 
317
      $out = dmidecode2array( $contents );
-
 
318
      // dump it
-
 
319
      print_r( $out );
-
 
320
   } else {
-
 
321
      print "You must pass the file as the first command line parameter\n";
256
   }
322
   }
257
   return array( $return );
-
 
258
}  // dmidecode2array
-
 
259
 
323
 
-
 
324
   remove this line for testing */
260
 
325
 
261
$filename = $argv[1];
-
 
262
if ( $filename ) {
-
 
263
   $contents = file( $filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
-
 
264
   $out = dmidecode2array( $contents );
-
 
265
   print_r( $out );
-
 
266
} else {
-
 
267
   print "You must pass the file as the first command line parameter\n";
-
 
268
}
326
?>