forked from opendcim/openDCIM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvmnamecheck.php
148 lines (124 loc) · 5.48 KB
/
vmnamecheck.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
require_once('db.inc.php');
require_once('facilities.inc.php');
require_once('swiftmailer/swift_required.php');
$esx=new ESX();
$dev=new Device();
$dept=new Department();
$error="";
// If any port other than 25 is specified, assume encryption and authentication
if($config->ParameterArray['SMTPPort']!= 25){
$transport=Swift_SmtpTransport::newInstance()
->setHost($config->ParameterArray['SMTPServer'])
->setPort($config->ParameterArray['SMTPPort'])
->setEncryption('ssl')
->setUsername($config->ParameterArray['SMTPUser'])
->setPassword($config->ParameterArray['SMTPPassword']);
}else{
$transport=Swift_SmtpTransport::newInstance()
->setHost($config->ParameterArray['SMTPServer'])
->setPort($config->ParameterArray['SMTPPort']);
}
$mailer=Swift_Mailer::newInstance($transport);
$message=Swift_Message::NewInstance()->setSubject(__("Virtual Machine Inventory Exception Report"));
// Set from address
try{
$message->setFrom($config->ParameterArray['MailFromAddr']);
$message->SetReplyTo($config->ParameterArray["MailToAddr"]);
}catch(Swift_RfcComplianceException $e){
$error.=__("MailFrom").": <span class=\"errmsg\">".$e->getMessage()."</span><br>\n";
}
// Add people to recipient list
try{
$message->setTo($config->ParameterArray['MailToAddr']);
/* // Add additional recipients below this section using the following examples
* // Using addTo() to add recipients iteratively
* $message->addTo('[email protected]');
* $message->addTo('[email protected]', 'Person 2 Name');
*/
}catch(Swift_RfcComplianceException $e){
$error.=__("Data center team address").": <span class=\"errmsg\">".$e->getMessage()."</span><br>\n";
}
// Send email about Virtual Machines that don't have owners assigned
$esxList=$esx->GetOrphanVMList($facDB);
if(count($esxList) >0){
$esxCount=count($esxList);
$htmlMessage="<html>
<head>
<title>".__('Virtual Machine Inventory Exception Report')."</title>
</head>
<body>
<p>".__('This is an automated message from the')." {$config->ParameterArray["OrgName"]} ".__('Inventory
Process. This process is scheduled to run once each business day.</p>
<p>The following')." $esxCount ".__('Virtual Machines were detected in the environment
and do not have an associated owner record. It is assumed that
these are new Virtual Machines. Please click on the links below to update
ownership information.')."</p>
<p>".__('If the appropriate department is not listed as an option for ownership, please
send an email to')." {$config->ParameterArray["FacMgrMail"]} ".__('to have it added.')."</p>
<p>
<table width=\"100%\" border=\"1\" padding=\"0\" bgcolor=white>
<tr><td>".__('Server Name')."</td><td>".__('VM Name')."</td><td>".__('Status')."</td><td>".__('Last Updated')."</td></tr>";
foreach($esxList as $esxRow){
$dev->DeviceID=$esxRow->DeviceID;
$dev->GetDevice($facDB);
$dept->DeptID=$esxRow->Owner;
if($dept->DeptID >0){
$dept->GetDeptByID($facDB);
}else{
$dept->Name=__("Unknown");
}
$htmlMessage.="<tr><td>$dev->Label</td><td><a href=\"".redirect("updatevmowner.php?vmindex=$esxRow->VMIndex")."\">$esxRow->vmName</a></td><td>$esxRow->vmState</td><td>$esxRow->LastUpdated</td></tr>\n";
}
$htmlMessage.="</table></body></html>";
$message->setBody($htmlMessage,'text/html');
try{
$result=$mailer->send($message);
}catch(Swift_RfcComplianceException $e){
$error.="Send: ".$e->getMessage()."<br>\n";
}catch(Swift_TransportException $e){
$error.="Server: <span class=\"errmsg\">".$e->getMessage()."</span><br>\n";
}
}
// Send email about Virtual Machines that are going to be pruned from inventory
$esxList=$esx->GetExpiredVMList($config->ParameterArray["VMExpirationTime"],$facDB);
if(count($esxList) >0){
$esxCount=count($esxList);
$htmlMessage="<html>
<head>
<title>".__('Virtual Machine Inventory Expiration Report')."</title>
</head>
<body>
<p>".__('This is an automated message from the')." {$config->ParameterArray["OrgName"]} ".__('Virtual Machine Inventory
Process. This process is scheduled to run once each business day.')."</p>
<p>".__('The following')." $esxCount ".__('Virtual Machines have not been detected within the
past')." {$config->ParameterArray["VMExpirationTime"]} ".__('days and are assumed to be expired. They are being removed from the
inventory system.')."</p>
<table width=\"100%\" border=\"1\" padding=\"0\" bgcolor=white>
<tr><td>".__('Server Name')."</td><td>".__('VM Name')."</td><td>".__('Status')."</td><td>".__('Last Updated')."</td></tr>";
foreach($esxList as $esxRow){
$dev->DeviceID=$esxRow->DeviceID;
$dev->GetDevice($facDB);
$dept->DeptID=$esxRow->Owner;
if($dept->DeptID >0){
$dept->GetDeptByID($facDB);
}else{
$dept->Name=__("Unknown");
}
$htmlMessage.="<tr><td>$dev->Label</td><td>$esxRow->vmName</td><td>$esxRow->vmState</td><td>$esxRow->LastUpdated</td></tr>\n";
}
$htmlMessage.="</table></body></html>";
$message->setBody($htmlMessage,'text/html');
try{
$result=$mailer->send($message);
}catch(Swift_RfcComplianceException $e){
$error.="Send: ".$e->getMessage()."<br>\n";
}catch(Swift_TransportException $e){
$error.="Server: <span class=\"errmsg\">".$e->getMessage()."</span><br>\n";
}
// Delete 'em
$esx->ExpireVMs($config->ParameterArray["VMExpirationTime"],$facDB);
}
// output any errors so they might get recorded someplace
echo $error;
?>