23 |
rodolico |
1 |
This is designed to capture camp-sysinfo-client reports (v2 & v3) which have been sent via e-mail.
|
|
|
2 |
|
|
|
3 |
That would run the doReports.pl perl script that does the following:
|
|
|
4 |
|
|
|
5 |
NOTE: The system assumes you have installed sendEmail.pl written by Brandon Zehm. This is a Perl script, somewhat old but still works very, very well. It can be downloaded from
|
|
|
6 |
http://caspian.dotconf.net/menu/Software/SendEmail/
|
|
|
7 |
There is a bug I don't like in this 2009 script, but a copy of the patched script should be available with CAMP. Place this file someplace (I use /opt/sendEmail/sendEmail.pl) and put the correct path in the configuration file.
|
|
|
8 |
|
|
|
9 |
The following scripts, and their purposes
|
|
|
10 |
|
|
|
11 |
doReports.pl
|
|
|
12 |
script which ties everything together; read the mail, process the report into the database, then store the file (after processing) wherever it needs to be.
|
|
|
13 |
A) uses getSysinfoMail.php to download all e-mail messages, storing them on disk with a name based on report date, client name, machine name and serial number. The file will have a yaml/xml/ini suffix based on its type.
|
|
|
14 |
B) for each sorted list of files (sorted by file name, so date, then client name, then machine name, then serial number), send the file to be processed by parse_sysinfo.php
|
|
|
15 |
C) When file is processed, it is moved to a directory based on what the processor says. If it was successfuly processed, it is placed in a directory tree (year/month/file).
|
|
|
16 |
D) A report is sent to the administrator using sendEmail.pl
|
|
|
17 |
|
|
|
18 |
getSysinfoMail.php
|
|
|
19 |
Reads mail from one or more e-mail accounts, looking for sysinfo reports. When one is found, it is downloaded and parsed, then placed in an "unprocessed" directory. The target file is named as follows:
|
|
|
20 |
Report Date + Client Name + Machine Name + Serial Number
|
|
|
21 |
all separated by underscores. These values are taken from the report itself. Additionally, the file timestamp is set to the report date.
|
|
|
22 |
The appropriate suffix is added to the file (.yaml, .xml or .ini)
|
|
|
23 |
If requested in the configuration file, once successfully brought down to the local machine, it is deleted from the mail server.
|
|
|
24 |
|
|
|
25 |
library.php
|
|
|
26 |
This is the standard php library used by a lot of my scripts. I replicated it here so it could be immediately available instead of trying to find it. Sloppy, but I'll fix it later.
|
|
|
27 |
|
|
|
28 |
parse_sysinfo.php
|
|
|
29 |
Script reads ONE file, either passed as a parameter on the command line, or more generally from STDIN. It then processes it as a sysinfo report, placing the resulting values in the database.
|
|
|
30 |
Script detects whether a report is valid, duplicate, new or invalid and returns a value based on that (see doReports.pl or this script). This value then allows doReports.pl to determine which directory to move it to.
|
|
|
31 |
Script returns one or more lines of comments saying what happened in the script (ie, added new device, updated some software, etc...)
|
|
|
32 |
|
|
|
33 |
sysinfoRead.conf-creator.php
|
|
|
34 |
I decided to use YAML for the configuration file, due to its portability. However, I suck at YAML, so I wrote the configuration file up as a PHP file, then added a line to convert that to YAML. Cheat!
|
|
|
35 |
|
|
|
36 |
sysinfoRead.conf.yaml
|
|
|
37 |
This is the main configuration file for the scripts, in a YAML format. I chose this since there are libraries for PHP and Perl (and most other languages) to import it, so it is language neutral.
|
|
|
38 |
This file contains SENSITIVE INFORMATION and should be set 600 in a directory secured against intruston. It contains username/password for one or more e-mail accounts.
|
|
|
39 |
The location of this file can be in any of the following directories /etc/camp, /opt/camp, /opt/camp/sysinfo, $_SERVER['SCRIPT_FILENAME'], getcwd(). They are searched in order, and the first one found is used.
|
|
|
40 |
|
|
|
41 |
INSTALLATION (recommended)
|
|
|
42 |
create a symbolic link of the cli directory to /opt/camp/sysinfo
|
|
|
43 |
In a separate location, modify sysinfoRead.conf-creator.php to meet your needs, then run it, piping the output to /etc/camp/sysinfoRead.conf.yaml
|
|
|
44 |
Test the installation
|
|
|
45 |
Create /etc/cron.d/sysinforeports with the following contents
|
|
|
46 |
----------------------------------------------------------------------
|
|
|
47 |
# Run sysinfo reports at 3pm every day
|
|
|
48 |
|
|
|
49 |
----------------------------------------------------------------------
|
|
|
50 |
|
|
|
51 |
Note: myuser must have read access to /opt/camp/sysinfo/*, /etc/sysinfo/sysinfoRead.conf.yaml, sendEmail.pl, and full write access to datapath defined in the configuration file. The user must also be able to invoke perl and php.
|