6 |
rodolico |
1 |
<?php
|
|
|
2 |
/*
|
|
|
3 |
* This file is just an easy way to create the YAML configuration file.
|
|
|
4 |
* You, as a PHP programmer, are probably more familiar with PHP than
|
|
|
5 |
* YAML, so create an array, $configuration, below, then run this
|
|
|
6 |
* script (ie, php sysinfoRead.conf-creator.php). A properly formatted
|
|
|
7 |
* YAML configuration stream will be sent to STDOUT, where you can
|
|
|
8 |
* capture it.
|
|
|
9 |
* OF COURSE, you can definitely hand code the YAML. It is actually much
|
|
|
10 |
* simpler than doing the PHP, but not if you're familiar with PHP
|
|
|
11 |
* and not so good with YAML.
|
11 |
rodolico |
12 |
* Requires php-pear and libyaml under Debian Wheezy
|
|
|
13 |
*
|
|
|
14 |
* apt-get install php-pear php5-dev libyaml-dev libyaml-0-2 libyaml-0-2-dbg
|
|
|
15 |
* pecl install yaml
|
|
|
16 |
* echo 'extension=yaml.so' >> /etc/php5/cli/php.ini
|
|
|
17 |
* echo 'extension=yaml.so' >> /etc/apache2/cli/php.ini
|
|
|
18 |
*
|
6 |
rodolico |
19 |
*/
|
11 |
rodolico |
20 |
|
|
|
21 |
/*
|
|
|
22 |
I use a nowdoc to define this large block of code which evaluates an ini file.
|
|
|
23 |
(see http://php.net/manual/en/language.types.string.php#language.types.string.syntax.nowdoc
|
|
|
24 |
nowdoc's don't really work in an array, or at least I have not been able
|
|
|
25 |
to figure out the syntax, so I use the following to get the code into the variable
|
|
|
26 |
$eval_ini, then put that into the $configuration array.
|
|
|
27 |
Also, nowdoc's are pretty sloppy looking, so another reason to do it here :)
|
|
|
28 |
*/
|
|
|
29 |
$eval_ini = <<<'END'
|
|
|
30 |
$data = array();
|
|
|
31 |
preg_match( '/\[report date\](.*)[\r\n]/', $body, $_date );
|
|
|
32 |
preg_match( '/\[client name\](.*)[\r\n]/', $body, $_client );
|
|
|
33 |
preg_match( '/\[hostname\](.*)[\r\n]/', $body, $_host );
|
|
|
34 |
$data['report']['date'] = str_replace(array("\n", "\r"), '', $_date[1]);
|
|
|
35 |
$data['report']['client'] = str_replace(array("\n", "\r"), '', $_client[1]);
|
|
|
36 |
$data['system']['hostname'] = str_replace(array("\n", "\r"), '', $_host[1]);
|
|
|
37 |
return $data;
|
|
|
38 |
END;
|
|
|
39 |
// end of the nowdoc, now on to the regular stuff
|
|
|
40 |
|
6 |
rodolico |
41 |
// Configuration file for getSysinfoMail.php, parse_sysinfo.php and other files
|
|
|
42 |
$configuration = array(
|
|
|
43 |
// set this to where the files parsed from mail should be placed.
|
|
|
44 |
'outpath' => '/home/rodolico/temp/sysinfo_reports/unprocessed',
|
|
|
45 |
'logFile' => '/home/rodolico/temp/sysinfo_reports/errors.log',
|
|
|
46 |
'datapath' => '/home/rodolico/temp/sysinfo_reports',
|
|
|
47 |
'unprocessed_path' => 'unprocessed',
|
|
|
48 |
'getMailScript' => 'getSysinfoMail.php',
|
|
|
49 |
'processMailScript' => 'parse_sysinfo.php',
|
|
|
50 |
|
|
|
51 |
|
|
|
52 |
// server connection information
|
|
|
53 |
|
|
|
54 |
'servers' => array(
|
|
|
55 |
array (
|
|
|
56 |
'servername' => 'book.dailydata.net',
|
|
|
57 |
'port' => 143,
|
|
|
58 |
'ssl' => false,
|
|
|
59 |
'mailbox' => '.Processed',
|
|
|
60 |
'username' => 'serverstats',
|
|
|
61 |
'password' => 'sachemic',
|
|
|
62 |
'deleteProcessed' => false,
|
|
|
63 |
'enabled' => false
|
|
|
64 |
),
|
|
|
65 |
array (
|
|
|
66 |
'servername' => 'book.dailydata.net',
|
|
|
67 |
'port' => 143,
|
|
|
68 |
'ssl' => false,
|
|
|
69 |
'mailbox' => 'Processed.2011',
|
|
|
70 |
'username' => 'serverstats',
|
|
|
71 |
'password' => 'sachemic',
|
|
|
72 |
'deleteProcessed' => true,
|
|
|
73 |
'enabled' => false
|
|
|
74 |
),
|
|
|
75 |
|
|
|
76 |
array (
|
|
|
77 |
'servername' => 'book.dailydata.net',
|
|
|
78 |
'port' => 143,
|
|
|
79 |
'ssl' => false,
|
|
|
80 |
'mailbox' => 'Processed.2012',
|
|
|
81 |
'username' => 'serverstats',
|
|
|
82 |
'password' => 'sachemic',
|
|
|
83 |
'deleteProcessed' => true,
|
|
|
84 |
'enabled' => false
|
|
|
85 |
),
|
|
|
86 |
|
|
|
87 |
array (
|
|
|
88 |
'servername' => 'book.dailydata.net',
|
|
|
89 |
'port' => 143,
|
|
|
90 |
'ssl' => false,
|
|
|
91 |
'mailbox' => 'Processed.2013',
|
|
|
92 |
'username' => 'serverstats',
|
|
|
93 |
'password' => 'sachemic',
|
|
|
94 |
'deleteProcessed' => true,
|
|
|
95 |
'enabled' => false
|
|
|
96 |
),
|
|
|
97 |
|
|
|
98 |
array (
|
|
|
99 |
'servername' => 'book.dailydata.net',
|
|
|
100 |
'port' => 143,
|
|
|
101 |
'ssl' => false,
|
|
|
102 |
'mailbox' => 'Processed.2014',
|
|
|
103 |
'username' => 'serverstats',
|
|
|
104 |
'password' => 'sachemic',
|
|
|
105 |
'deleteProcessed' => true,
|
|
|
106 |
'enabled' => false
|
|
|
107 |
),
|
|
|
108 |
|
|
|
109 |
array (
|
|
|
110 |
'servername' => 'book.dailydata.net',
|
|
|
111 |
'port' => 143,
|
|
|
112 |
'ssl' => false,
|
|
|
113 |
'mailbox' => 'Processed.2015',
|
|
|
114 |
'username' => 'serverstats',
|
|
|
115 |
'password' => 'sachemic',
|
|
|
116 |
'deleteProcessed' => true,
|
|
|
117 |
'enabled' => false
|
|
|
118 |
),
|
|
|
119 |
|
|
|
120 |
array (
|
|
|
121 |
'servername' => 'smtp.dailydata.net',
|
|
|
122 |
'port' => 143,
|
|
|
123 |
'ssl' => false,
|
|
|
124 |
'mailbox' => 'INBOX',
|
|
|
125 |
'username' => 'stats@dailydata.net',
|
|
|
126 |
'password' => 'los,vce',
|
|
|
127 |
'deleteProcessed' => false,
|
|
|
128 |
'enabled' => false
|
|
|
129 |
),
|
|
|
130 |
|
|
|
131 |
array (
|
|
|
132 |
'servername' => 'smtp.dailydata.net',
|
|
|
133 |
'port' => 143,
|
|
|
134 |
'ssl' => false,
|
|
|
135 |
'mailbox' => 'INBOX',
|
|
|
136 |
'username' => 'test@dailydata.net',
|
|
|
137 |
'password' => 'los,vce',
|
|
|
138 |
'deleteProcessed' => true,
|
|
|
139 |
'enabled' => true
|
|
|
140 |
)
|
|
|
141 |
),
|
|
|
142 |
|
|
|
143 |
// these are regex's that define what we want to capture. Everything between startKey and endKey, inclusive
|
|
|
144 |
// we then process it with eval, which is an anonymous function accepting one paramter (body) and returning
|
|
|
145 |
// the array represented by the associated data definition
|
|
|
146 |
'bodyContents' => array(
|
|
|
147 |
'xml' => array(
|
|
|
148 |
'startTag' => '\<sysinfo',
|
|
|
149 |
'endTag' => '\<\/sysinfo[^>]*\>',
|
|
|
150 |
// see http://stackoverflow.com/questions/6578832/how-to-convert-xml-into-array-in-php
|
11 |
rodolico |
151 |
'eval' => 'return(json_decode(json_encode((array)simplexml_load_string($body)),1));',
|
6 |
rodolico |
152 |
|
|
|
153 |
),
|
|
|
154 |
'yaml' => array(
|
|
|
155 |
'startTag' => '\-\-\-',
|
|
|
156 |
'endTag' => '\.\.\.',
|
11 |
rodolico |
157 |
'eval' => 'return( yaml_parse( $body, 0 ) );',
|
6 |
rodolico |
158 |
),
|
|
|
159 |
'ini' => array( # this is an older format which we don't support, so we'll just write it out
|
|
|
160 |
'startTag' => '\[sysinfo version\]',
|
11 |
rodolico |
161 |
'endTag' => '',
|
|
|
162 |
'eval' => $eval_ini,
|
6 |
rodolico |
163 |
)
|
|
|
164 |
),
|
|
|
165 |
|
|
|
166 |
'datase' => array(
|
|
|
167 |
'databaseServer' => 'localhost',
|
|
|
168 |
'databaseUsername' => 'camp',
|
|
|
169 |
'databasePassword' => 'camp',
|
|
|
170 |
'database' => 'camp',
|
|
|
171 |
),
|
|
|
172 |
'sendReport' => array(
|
|
|
173 |
'emailScript'=>'/opt/sendEmail/sendEmail.pl',
|
|
|
174 |
'mailTo'=> 'rodo@dailydata.net',
|
|
|
175 |
'mailServer' => 'smtp.dailydata.net:587',
|
|
|
176 |
'mailSubject' => 'Sysinfo Report',
|
|
|
177 |
'mailFrom' => 'sysinfo@dailydata.net',
|
|
|
178 |
'logFile' => '/tmp/mail.log',
|
|
|
179 |
'tls' => "'auto'",
|
|
|
180 |
'smtpUser' => 'stats@dailydata.net',
|
|
|
181 |
'smtpPass' => 'UrLnuCp@G85',
|
|
|
182 |
),
|
|
|
183 |
|
|
|
184 |
);
|
|
|
185 |
|
|
|
186 |
// here is where we actually generate the YAML
|
|
|
187 |
print yaml_emit( $configuration );
|
|
|
188 |
|
|
|
189 |
|
|
|
190 |
?>
|