Rev 11 | 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.
// note, outpath will be removed in the future. It should be 'datapath/unprocessed_path'
// until that is done.
// in the future, datapath will define a root, then everything will be a subdirectory
// of that; unprocessed, duplicate, and all processed files
// processed files will be in datapath/YYYY/MM/filename
'outpath' => '/path/to/unprocessed/email', // this should be 'datapath/unprocessed_path'
'logFile' => '/path/to/log/file/errors.log', // full path to an error file
'datapath' => '/path/to/root/of/reports', // the root of all files
'unprocessed_path' => 'unprocessed', // subdirectory of datapath
'getMailScript' => 'getSysinfoMail.php', // name of the mail getter script
'processMailScript' => 'parse_sysinfo.php', // name of the report parser
'reportScript' => 'sendReport.pl', // name of the report script
// server connection information
// you can check multiple servers, accounts and mailboxes (folders)
// only two are listed here, but it can be from one to however many you want
'servers' => array(
array (
'servername' => 'smtp.server.or.ip',
'port' => 143,
'ssl' => false,
'mailbox' => 'mailbox.name',
'username' => 'username',
'password' => 'password',
'deleteProcessed' => false, // true will delete once they are downloaded
'enabled' => false // false means this entry will be ignored
),
array (
'servername' => 'smtp.server.or.ip',
'port' => 143,
'ssl' => false,
'mailbox' => 'mailbox.name',
'username' => 'username',
'password' => 'password',
'deleteProcessed' => false, // true will delete once they are downloaded
'enabled' => false // false means this entry will be ignored
),
),
// your database connection information
'datase' => array(
'databaseServer' => 'localhost',
'databaseUsername' => 'dbuser',
'databasePassword' => 'dbpass',
'database' => 'dbname',
),
// you really need sendEmail.pl for this to work, as I've really written this around that
// see README.txt. This sends the report at the end of the processing. You can comment out
// the call to sendReport.pl in doReports.pl or rewrite the former.
'sendReport' => array(
'emailScript'=>'/opt/sendEmail/sendEmail.pl',
'mailTo'=> 'who@gets.mail',
'mailServer' => 'smtp.server.com:587',
'mailSubject' => 'Sysinfo Report',
'mailFrom' => 'sysinfo@mydomain.org',
'logFile' => '/tmp/mail.log',
'tls' => "'auto'",
'smtpUser' => 'smtp@user.com', // for authenticated SMTP
'smtpPass' => 'password', // for authenticated SMTP
),
// You really should not modify the following unless you know what you are doing
// 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,
)
),
);
// here is where we actually generate the YAML
print yaml_emit( $configuration );
?>