Subversion Repositories computer_asset_manager_v1

Rev

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

Rev 97 Rev 98
Line 1... Line 1...
1
<?php
1
<?php
2
 
2
 
3
 
3
 
-
 
4
function cleanUpDMIValue( $value ) {
-
 
5
   $value = trim( $value );
-
 
6
   switch (strtolower( $value )) {
-
 
7
      case 'unknown':
-
 
8
      case 'not available':
-
 
9
      case 'not specified': return '';
-
 
10
   }
-
 
11
   return $value;
-
 
12
}
-
 
13
 
4
/*
14
/*
5
 * Read value from hash, return $outputKey\tvalue from hash
15
 * Read value from hash, return $outputKey\tvalue from hash
6
 * Or, empty string if not found
16
 * Or, empty string if not found
7
 */
17
 */
8
function getDMIInformation( $data, $type, $handle, $key, $outputKey = '' ) {
18
function getDMIInformation( $data, $type, $handle, $key, $outputKey = '' ) {
9
   if ( isset( $data[$type][$handle][$key] ) ) {
19
   if ( isset( $data[$type][$handle][$key]) ) {
10
      return ( $outputKey ? $outputKey : $key ) . "\t" . $data[$type][$handle][$key];
20
      $a = cleanUpDMIValue( $data[$type][$handle][$key] );
11
   } else {
21
      if ( $a )
12
      return '';
22
         return ( $outputKey ? $outputKey : $key ) . "\t" . $a;
13
   }
23
   }
-
 
24
   return '';
14
}
25
}
15
 
26
 
16
 
27
 
17
/*
28
/*
18
 * Function will take an array of lines representing the output of a dmidecode file
29
 * Function will take an array of lines representing the output of a dmidecode file
Line 128... Line 139...
128
   if ( $temp ) $return[] = $temp;
139
   if ( $temp ) $return[] = $temp;
129
   $temp = &getDMIInformation( $data, '0','0x0000','Version', 'Firmware Version' );
140
   $temp = &getDMIInformation( $data, '0','0x0000','Version', 'Firmware Version' );
130
   if ( $temp ) $return[] = $temp;
141
   if ( $temp ) $return[] = $temp;
131
   $temp = &getDMIInformation( $data, '0','0x0000','Firmware Revision', 'Firmware Revision' );
142
   $temp = &getDMIInformation( $data, '0','0x0000','Firmware Revision', 'Firmware Revision' );
132
   if ( $temp ) $return[] = $temp;
143
   if ( $temp ) $return[] = $temp;
-
 
144
   // physical size
133
   $temp = &getDMIInformation( $data, '3','0x0300','Firmware Revision', 'Enclosure Type' );
145
   $temp = &getDMIInformation( $data, '3','0x0300','Type', 'Enclosure Type' );
-
 
146
   if ( $temp ) $return[] = $temp;
-
 
147
   $temp = &getDMIInformation( $data, '3','0x0300','Asset Tag', 'Enclosure Asset Tag' );
134
   if ( $temp ) $return[] = $temp;
148
   if ( $temp ) $return[] = $temp;
135
   $temp = &getDMIInformation( $data, '3','0x3000','Asset Tag' );
149
   $temp = &getDMIInformation( $data, '3','0x0300','Height', 'Enclosure Height' );
136
   if ( $temp ) $return[] = $temp;
150
   if ( $temp ) $return[] = $temp;
137
   // processor information
151
   // processor information
138
   if ( isset( $data['4'] ) )
152
   if ( isset( $data['4'] ) )
139
      $return[] = "CPU Count\t" . count( $data['4'] ); // fails if there are unpopulated slots or disabled ones
153
      $return[] = "CPU Count\t" . count( $data['4'] ); // fails if there are unpopulated slots or disabled ones
140
      
154
      
Line 209... Line 223...
209
      }
223
      }
210
   }
224
   }
211
   return array( $return );
225
   return array( $return );
212
}
226
}
213
 
227
 
214
function cleanUpDMIValue( $value ) {
-
 
215
   $value = trim( $value );
-
 
216
   switch (strtolower( $value )) {
-
 
217
      case 'unknown':
-
 
218
      case 'not available':
-
 
219
      case 'not specified': return '';
-
 
220
   }
-
 
221
   return $value;
-
 
222
}
-
 
223
 
-
 
224
$filename = $argv[1];
228
$filename = $argv[1];
225
if ( $filename ) {
229
if ( $filename ) {
226
   $contents = file( $filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
230
   $contents = file( $filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
227
   $out = dmidecode2array( $contents );
231
   $out = dmidecode2array( $contents );
228
   print_r( $out );
232
   print_r( $out );