Rev 6 | Rev 12 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
<?php
/*
* This file is just an easy way to create the YAML configuration file.
* You, as a PHP programmer, are probably more familiar with PHP than
* YAML, so create an array, $configuration, below, then run this
* script (ie, php sysinfoRead.conf-creator.php). A properly formatted
* YAML configuration stream will be sent to STDOUT, where you can
* capture it.
* OF COURSE, you can definitely hand code the YAML. It is actually much
* simpler than doing the PHP, but not if you're familiar with PHP
* and not so good with YAML.
* Requires php-pear and libyaml under Debian Wheezy
*
* apt-get install php-pear php5-dev libyaml-dev libyaml-0-2 libyaml-0-2-dbg
* pecl install yaml
* echo 'extension=yaml.so' >> /etc/php5/cli/php.ini
* echo 'extension=yaml.so' >> /etc/apache2/cli/php.ini
*
*/
/*
I use a nowdoc to define this large block of code which evaluates an ini file.
(see http://php.net/manual/en/language.types.string.php#language.types.string.syntax.nowdoc
nowdoc's don't really work in an array, or at least I have not been able
to figure out the syntax, so I use the following to get the code into the variable
$eval_ini, then put that into the $configuration array.
Also, nowdoc's are pretty sloppy looking, so another reason to do it here :)
*/
$eval_ini = <<<'END'
$data = array();
preg_match( '/\[report date\](.*)[\r\n]/', $body, $_date );
preg_match( '/\[client name\](.*)[\r\n]/', $body, $_client );
preg_match( '/\[hostname\](.*)[\r\n]/', $body, $_host );
$data['report']['date'] = str_replace(array("\n", "\r"), '', $_date[1]);
$data['report']['client'] = str_replace(array("\n", "\r"), '', $_client[1]);
$data['system']['hostname'] = str_replace(array("\n", "\r"), '', $_host[1]);
return $data;
END;
// end of the nowdoc, now on to the regular stuff
// Configuration file for getSysinfoMail.php, parse_sysinfo.php and other files
$configuration = array(
// set this to where the files parsed from mail should be placed.
'outpath' => '/home/rodolico/temp/sysinfo_reports/unprocessed',
'logFile' => '/home/rodolico/temp/sysinfo_reports/errors.log',
'datapath' => '/home/rodolico/temp/sysinfo_reports',
'unprocessed_path' => 'unprocessed',
'getMailScript' => 'getSysinfoMail.php',
'processMailScript' => 'parse_sysinfo.php',
// server connection information
'servers' => array(
array (
'servername' => 'book.dailydata.net',
'port' => 143,
'ssl' => false,
'mailbox' => '.Processed',
'username' => 'serverstats',
'password' => 'sachemic',
'deleteProcessed' => false,
'enabled' => false
),
array (
'servername' => 'book.dailydata.net',
'port' => 143,
'ssl' => false,
'mailbox' => 'Processed.2011',
'username' => 'serverstats',
'password' => 'sachemic',
'deleteProcessed' => true,
'enabled' => false
),
array (
'servername' => 'book.dailydata.net',
'port' => 143,
'ssl' => false,
'mailbox' => 'Processed.2012',
'username' => 'serverstats',
'password' => 'sachemic',
'deleteProcessed' => true,
'enabled' => false
),
array (
'servername' => 'book.dailydata.net',
'port' => 143,
'ssl' => false,
'mailbox' => 'Processed.2013',
'username' => 'serverstats',
'password' => 'sachemic',
'deleteProcessed' => true,
'enabled' => false
),
array (
'servername' => 'book.dailydata.net',
'port' => 143,
'ssl' => false,
'mailbox' => 'Processed.2014',
'username' => 'serverstats',
'password' => 'sachemic',
'deleteProcessed' => true,
'enabled' => false
),
array (
'servername' => 'book.dailydata.net',
'port' => 143,
'ssl' => false,
'mailbox' => 'Processed.2015',
'username' => 'serverstats',
'password' => 'sachemic',
'deleteProcessed' => true,
'enabled' => false
),
array (
'servername' => 'smtp.dailydata.net',
'port' => 143,
'ssl' => false,
'mailbox' => 'INBOX',
'username' => 'stats@dailydata.net',
'password' => 'los,vce',
'deleteProcessed' => false,
'enabled' => false
),
array (
'servername' => 'smtp.dailydata.net',
'port' => 143,
'ssl' => false,
'mailbox' => 'INBOX',
'username' => 'test@dailydata.net',
'password' => 'los,vce',
'deleteProcessed' => true,
'enabled' => true
)
),
// these are regex's that define what we want to capture. Everything between startKey and endKey, inclusive
// we then process it with eval, which is an anonymous function accepting one paramter (body) and returning
// the array represented by the associated data definition
'bodyContents' => array(
'xml' => array(
'startTag' => '\<sysinfo',
'endTag' => '\<\/sysinfo[^>]*\>',
// see http://stackoverflow.com/questions/6578832/how-to-convert-xml-into-array-in-php
'eval' => 'return(json_decode(json_encode((array)simplexml_load_string($body)),1));',
),
'yaml' => array(
'startTag' => '\-\-\-',
'endTag' => '\.\.\.',
'eval' => 'return( yaml_parse( $body, 0 ) );',
),
'ini' => array( # this is an older format which we don't support, so we'll just write it out
'startTag' => '\[sysinfo version\]',
'endTag' => '',
'eval' => $eval_ini,
)
),
'datase' => array(
'databaseServer' => 'localhost',
'databaseUsername' => 'camp',
'databasePassword' => 'camp',
'database' => 'camp',
),
'sendReport' => array(
'emailScript'=>'/opt/sendEmail/sendEmail.pl',
'mailTo'=> 'rodo@dailydata.net',
'mailServer' => 'smtp.dailydata.net:587',
'mailSubject' => 'Sysinfo Report',
'mailFrom' => 'sysinfo@dailydata.net',
'logFile' => '/tmp/mail.log',
'tls' => "'auto'",
'smtpUser' => 'stats@dailydata.net',
'smtpPass' => 'UrLnuCp@G85',
),
);
// here is where we actually generate the YAML
print yaml_emit( $configuration );
?>