E-mail Notification
-
Hi Guys,
is there anyway to get FOG to send an e-mail once an image task has started/completed? i’m sure i saw someone do this on the old forum but didn’t need the facility at the time. wondered if anyone else already has this setup? going to use it as a call logging system can automatically create calls from e-mails.
could anyone point me in the right direction?
P.s didn’t post it into the general support as (i believe) it’s not in FOG so it’s also a feature request…
-
anyone??
-
I think that develope it is really easy.
There are tree web service (they are located in WEBROOT_DIRECTORY/fog/service):
[LIST]
[]Pre_Stage1.php . This web service is called when a task begins.
[]Post_Stage2.php . This web service is called when an upload task ends .
[*]Post_Stage3.php . This web service is called when an download task ends .
[/LIST]Those web services are called by fog script either when you upload either when you download an image. Those web services responde with an echo (##), if the proccess finishes well. You can call to the [I][B]mail[/B][/I] php function (you can see the sintaxis [URL=‘http://php.net/manual/en/function.mail.php’]here*[/URL] ) to send an email. You must call it before the echo.
===============================
-
hi, got this working perfectly now thanks for pointing me in the right direction! the only thing i need to do in Post_Stage3.php is get the hostname to put into the mail function as Post_Stage3.php only pulls hostid and i’m having a complete mental block on how to get hostname without creating a new function or mysql connection. i know the functions there but cannot remember! lol
-
You don’t need create a new query to know the hostname. Probably, the fog script knows the hostname, it is necesary to change it when you download an image. Check the PXE file to know it.
Then, you can change the web service call:
[CODE]wget -q -O /tmp/co.txt “http://${web}service/Post_Stage3.php?mac=$mac&imgid=$imgid&hostname=$hostname” &>/dev/null[/CODE]
Capture the hostname in the Post_Stage3.php file:
[PHP]$hostname = $_GET[“hostname”];[/PHP] -
of course!! thank you, as I say stupid mental block! lol
-
This post is deleted! -
this didn’t work hostname is blank
-
want to try and avoid writing a new query but unless you got any other idea?.. thanks for the help btw
-
[quote=“Lee Rowlett, post: 12364, member: 28”]this didn’t work hostname is blank[/quote]
What is the reason to be blank? The PXE file hasn’t the hostname, the fog script not get the $hostname or the $_GET variable is empty?
-
The PXE file hasn’t the hostname
-
There is the problem You can solve it easily.
When you create a task, the webUI calls to tasks.confirm.include.php ( you can locete it in WEBROOT_DIRECTORY/fog/management/includes/ ). This php file creates the PXE file depending the tasks type. For example, to create a multicast download task, the tasks.confirm.include.php calls to :
[PHP]$taskid = createImagePackageMulticast($conn, $imageMembers[$i], $taskName, $port, $tmp, (!empty($_GET[“debug”]) && $_GET[“debug”] == “true” ), true, $shutdown, $imageMembers[$i]->getKernel(), $other , (empty($bashscript)? “”:$bashscript), $type, $taskPCT);[/PHP]
This function uses the [B][I]$other[/I][/B] variable to setup the hostname, check if this variable has setup the hostname.
-
Hi,
nice thread very interesting, @Lee do you have it working now?
Can you post a little overview of what u’ve done please?Greetz X23
-
[quote=“x23piracy, post: 12383, member: 3982”]Hi,
nice thread very interesting, @Lee do you have it working now?
Can you post a little overview of what u’ve done please?Greetz X23[/quote]
yes this would be very useful if you could share an overview, maybe if you could post it in the tutorial section?
-
Hi,
i have got it working but had to write a seperate query to get hostname. it is hard to write a step by step as you can customize it to however you want and use any mail protocol, i am using sendmail/mailutils - below is what i did.
edit the file …/fog/service/Post_Stage3.php
just before line: echo “##”; write you’re mail function i.e.
if ( checkOut( $conn, $jobid ) )
{
[B]mail(“emailaddress@tosendto”,“$hostname - Image Task Completed”, “$hostname has been successfully imaged”);[/B]
echo “##”;// Now update the imaging log.
@logImageTask( $conn, “e”, $hostid );if you would like to get the hostname in the email - you have to include this, it is another query and there may be a cleaner way to do this but for now put this anywhere before the if statement put…
$hst = “SELECT hostName FROM hosts WHERE hostID like '”.$hostid.“'”;
$res1 = mysql_query( $hst, $conn ) or die( mysql_error() );
$ar1 = mysql_fetch_object($res1);
$hostname = $ar1->hostName;optional:
on the server install sendmail/mailutils
apt-get install sendmail
apt-get install mailutilsrecommend stopping sendmail running a daemon.
hope this helps
…thanks for the guidance Fernando
-
-
Hi,
something about this ? Is it in the last version of fog ?
thx -
It’s added.
-
hi,
I was searching for that option and I realised that I was not in the same last version… I was in the 1.2.0 and not in the svn version. I m now in 1.2.0 version 3118 and I see a section “Fog Email Settings”. I think it s that but how does it work ?
The package has been installed but i m not receiving mails…
apt-get install sendmail
apt-get install mailutilsthx
-
Do you see any errors in your apache log files when mail is being sent? I guess you need to configure smart host with sendmail… [url]https://www.dnsexit.com/support/mailrelay/sendmail.html[/url]