Difference between revisions of "stoney cloud: Notification Architecture"

From stoney cloud
Jump to: navigation, search
[unchecked revision][unchecked revision]
(Graphical Workflow)
(Graphical Workflow)
 
(11 intermediate revisions by one other user not shown)
Line 104: Line 104:
 
== File System ==
 
== File System ==
 
In addition to the above explained LDAP Directory entries, the templates specified in '''sstMailTemplate''' and '''sstMailTemplateReseller''' must be present on the local file system. The notification script would throw an warning if they do not exist (or have wrong permission), but for the notification to work they must be present.
 
In addition to the above explained LDAP Directory entries, the templates specified in '''sstMailTemplate''' and '''sstMailTemplateReseller''' must be present on the local file system. The notification script would throw an warning if they do not exist (or have wrong permission), but for the notification to work they must be present.
 +
 +
= Configuration =
 +
The notification needs the following configuration:
 +
* Notification
 +
** Backend_service_base: The base object in the backend (LDAP) which contains all services
 +
** People_base: The base object in the backend (LDAP) which contains all people
 +
** Resller_base: The base object in the backend (LDAP) which contains all reseller
 +
** Default_mail_to: If something goes terribly wrong and no-one can be informed write a mail to this address
 +
* Mail
 +
** Host: The mail host to use to send the notification messages
 +
** Port: The corresponding port
 +
** Username: The username to authenticate on the mail host
 +
** Password: The corresponding password
 +
For example:
 +
<pre>
 +
[Notification]
 +
Backend_service_base = ou=services,dc=stoney-cloud,dc=org
 +
People_base = ou=people,dc=stoney-cloud,dc=org
 +
Reseller_base = ou=reseller,dc=stoney-cloud,dc=org
 +
Default_mail_to = support@stoney-cloud.org
 +
 +
[Mail]
 +
Host = mail.tombstone.org
 +
Port = 587
 +
Username = <Sender-Email-Adderss>
 +
Password = verysecret
 +
</pre>
  
 
= Graphical Workflow =
 
= Graphical Workflow =
  
[[File:Notification-workflow.jpeg|500px|thumbnail|none|Figure 1: Workflow for the general notification process]]
+
[[File:Notification-workflow.jpeg|800px|thumbnail|none|Figure 1: Workflow for the general notification process]]
  
 
You can modify/update these interactions by editing [[File:Notification-workflow.xmi]] (you may need [http://uml.sourceforge.net/ Umbrello UML Modeller] diagram programme for KDE to display the content properly).
 
You can modify/update these interactions by editing [[File:Notification-workflow.xmi]] (you may need [http://uml.sourceforge.net/ Umbrello UML Modeller] diagram programme for KDE to display the content properly).
Line 113: Line 140:
 
= How to use the Notification.pm module =
 
= How to use the Notification.pm module =
 
Given the set up described in section [[#Requirements | requirements]]: <br/>
 
Given the set up described in section [[#Requirements | requirements]]: <br/>
Suppose you have the <code><Service></code> "notification" and the <code><Problem></code> "test". The template referenced in the LDAP (<code>ou=test,ou=templates,uid=<RESELLER>,ou=reseller,ou=configuration,ou=notification,ou=services,dc=stoney-cloud,dc=org</code>) looks like:  
+
Suppose you have the <code><Service></code> "notification" and the <code><Problem></code> "test". The template referenced in the LDAP (<code>ou=test,ou=templates,uid=<RESELLER>,ou=reseller,ou=configuration,ou=notification,ou=services,dc=stoney-cloud,dc=org</code>) looks like (the notification module uses the perl module [http://search.cpan.org/~mjd/Text-Template-1.46/lib/Text/Template.pm Text::Template]):  
 
<pre>
 
<pre>
Hello {name}
+
Hello {$name}
  
This is a notification test from {hostname}
+
This is a notification test from {$hostname}
  
 
Cheers
 
Cheers
Sysadm
+
{$writer}
 
</pre>
 
</pre>
 
You can now write a very simple perl script which will inform the user and the reseller for the service "notification" and the problem "test". All you need to do is:  
 
You can now write a very simple perl script which will inform the user and the reseller for the service "notification" and the problem "test". All you need to do is:  
Line 130: Line 157:
 
<source lang="perl">
 
<source lang="perl">
 
my $notification = Notification->new( service => "notification",  
 
my $notification = Notification->new( service => "notification",  
                                      problem => "test",
+
                                      problem => "test",
                                      product_uid => $uid,
+
                                      product_uid => $uid,
 
                                     );
 
                                     );
<source>
+
</source>
 +
* Tell the notification module to connect to the LDAP backend
 +
<source lang="perl">
 +
$notification->connectToBackend( $ldap_server,
 +
                                $ldap_port,
 +
                                $ldap_bind_dn,
 +
                                $ldap_bind_pw,
 +
                              );
 +
</source>
 +
* Create the replacement hash
 +
** As you know the template you can easily fill in the replacement hash
 +
<source lang="perl">
 +
my $replace_hash = {
 +
                      name => "World",
 +
                      hostname => $hostname,
 +
                      writer => "Sysadm",
 +
                  };
 +
</source>
 +
* Finally set the create replacement hash in our notification object and call the notification method
 +
<source lang="perl">
 +
# Set the replace hash for the notification object
 +
$notification->setReplaceHash( $replace_hash );
 +
     
 +
# And notify user and/or reseller
 +
$notification->notify();
 +
</source>
 +
 
 +
As you can see, it is pretty easy to use the notification module if you followed the set up as described in the [[#Requirements | requirements]] section.
 +
== Error handling ==
 +
After each method of the notification object, you might want to check whether or not there was an error by calling the <code>error</code> method (for example after connecting to the backend):
 +
<source lang="perl">
 +
$notification->connectToBackend( $ldap_server,
 +
                                $ldap_port,
 +
                                $ldap_bind_dn,
 +
                                $ldap_bind_pw,
 +
                              );
 +
 
 +
# Check if the backup connection could be established
 +
if ( $notification->error() )
 +
{
 +
    # Log what went wrong
 +
    if ( $debug )
 +
    {
 +
        print "Debug: Cannot connect to LDAP server $ldap_server: "
 +
            .$notification->error()."\n";
 +
    }
 +
       
 +
    syslog('err',"Cannot connect to LDAP server $ldap_server: "
 +
                .$notification->error() );
 +
}
 +
</source>
 +
<code>$notification->error()</code> returns the error message if there was an error. If no error occurred, <code>$notification->error()</code> returns a false value. There is also a method <code>$notification->errorCode()</code> which returns the error code (numeric value).
  
 
= Source Code =
 
= Source Code =

Latest revision as of 15:11, 27 June 2014

Overview

The pages describes the basic notification architecture and framework.

Its main goal is to provide a script (class) which implements all generic methods used by the different Self-Service Modules to inform the user and/or the reseller. When instantiating the notification object, you only need to provide three parameters:

  • The product/service UID (e.g. 4000004)
  • The service name (e.g. "backup")
  • The problem name (e.g. "quota")

According to these three parameters the notification script

  1. Connects to the LDAP directory
  2. Gets the reseller according to the product/service UID from the LDAP directory
  3. Gets the user and reseller template files (template path and file-ending) from the LDAP directory and according to the reseller
  4. Uses this template-file to instantiate a perl-template object
  5. Creates an empty replace-hash
    This empty hash must be set by the Self-Service Module script, using the setReplaceHash method.
  6. Checks if the user should be informed about the given problem (according to the LDAP directory)
    • If the user should be informed:
      • Gets the E-Mail address which should be used to inform the user (according to the LDAP directory)
      • Fills in the user template using the replace-hash
      • Sends the mail (in future it will be possible to use SMS instead) to the given address
  7. Checks if the reseller wants to be informed (according to the LDAP)
    • If the reseller should be informed:
      • Gets the E-Mail address which should be used to inform the reseller (according to the LDAP directory)
      • Fills in the reseller template using the replace-hash
      • Sends the mail (in future it will be possible to use SMS instead) to the given address

See also Graphical Workflow

Currently the following Self-Service Modules depend on this notification framework:

Requirements

OpenLDAP directory

Each service needs a notification entry in the form of:

dn: ou=notifications,uid=<RESELLER>,ou=reseller,ou=configuration,ou=<SERVICE>,ou=services,dc=stoney-cloud,dc=org

A settings entry in the form of:

dn: ou=settings,uid=<RESELLER>,ou=reseller,ou=configuration,ou=<SERVICE>,ou=services,dc=stoney-cloud,dc=org

One or more template entries in the form of:

dn: ou=<PROBLEM>,ou=templates,uid=<RESELLER>,ou=reseller,ou=configuration,ou=<SERVICE>,ou=services,dc=stoney-cloud,dc=org

Notifications

The following example shows the backup service notification entry for the reseller with the uid 4000000:

dn: ou=notifications,uid=4000000,ou=reseller,ou=configuration,ou=backup,ou=services,dc=stoney-cloud,dc=org
objectclass: top
objectclass: organizationalUnit
objectclass: sstNotificationObjectClass
ou: notifications
description: The sub tree stores the notification information for the (online) backup service for the reseller Reseller Ltd. with the uid 4000000. This information is used independently of the notification settings of the users.
sstMailTo: Support stepping stone GmbH <support@stepping-stone.ch>
sstNotificationWarning: quota
sstNotificationWarning: schedule
sstNotificationWarning: unsuccessful

Where

  • sstMailTo is the e-mail address to which the reseller notifications are sent
  • sstNotificationWarning indicates which notifications should be sent to the specified address (sstMailTo), in this the, the reseller would receive notifications concerning:
    • backup quota
    • backup schedule
    • backup unseccessful

Settings

The following example shows the backup service settings entry for the reseller with the uid 4000000:

dn: ou=settings,uid=4000000,ou=reseller,ou=configuration,ou=backup,ou=services,o=stepping-stone,c=ch
description: This sub tree stores the information about what can be modified in which scope.
objectClass: top
objectClass: organizationalUnit
objectClass: sstServiceSettingsObjectClass
ou: settings
preferredLanguage: de-CH
sstMailFrom: Support stepping stone GmbH <support@stepping-stone.ch>
...

Where

  • sstMailFrom is the e-mail address where the notification mail comes from
  • preferredLanguage the language in which the mail will be sent to the reseller

Templates

The following example shows the backup service quota template entry for the reseller with the uid 4000000:.

dn: ou=quota,ou=templates,uid=4000000,ou=reseller,ou=configuration,ou=backup,ou=services,o=stepping-stone,c=ch
description: This leaf contains the quota templates for the (online) backup service.
objectClass: top
objectClass: organizationalUnit
objectClass: sstTemplateSetup
ou: quota
sstMailFrom: Support stepping stone GmbH <support@stepping-stone.ch>
sstMailTemplate: file:///var/www/selfcare/htdocs/themes/selfcare.stepping-stone.ch/templates/services/backup/quota/quota_mail
sstMailTemplateFormatSource: txt
sstMailTemplateFormatTarget: txt
sstMailTemplateReseller: file:///var/www/selfcare/htdocs/themes/selfcare.stepping-stone.ch/templates/services/backup/quota/quota_mail_reseller
sstMailTemplateResellerFormatSource: txt
sstMailTemplateResellerFormatTarget: txt

Where

  • sstMailFrom is the e-mail address where the notification mail comes from
  • sstMailTemplate is the path to the notification mail (the one which is sent to the user) template
  • sstMailTemplateFormatSource is the format (file ending) of the notification mail (the one which is sent to the user) template
  • sstMailTemplateFormatTarget is the format (file ending) of the notification mail (the one which is sent to the user) text (all placeholders from the template are now replaced)
  • sstMailTemplateReseller is the path to the notification mail (the one which is sent to the reseller) template
  • sstMailTemplateResellerFormatSource is the format (file ending) of the notification mail (the one which is sent to the reseller) template
  • sstMailTemplateResellerFormatTarget is the format (file ending) of the notification mail (the one which is sent to the reseller) text (all placeholders from the template are now replaced)

File System

In addition to the above explained LDAP Directory entries, the templates specified in sstMailTemplate and sstMailTemplateReseller must be present on the local file system. The notification script would throw an warning if they do not exist (or have wrong permission), but for the notification to work they must be present.

Configuration

The notification needs the following configuration:

  • Notification
    • Backend_service_base: The base object in the backend (LDAP) which contains all services
    • People_base: The base object in the backend (LDAP) which contains all people
    • Resller_base: The base object in the backend (LDAP) which contains all reseller
    • Default_mail_to: If something goes terribly wrong and no-one can be informed write a mail to this address
  • Mail
    • Host: The mail host to use to send the notification messages
    • Port: The corresponding port
    • Username: The username to authenticate on the mail host
    • Password: The corresponding password

For example:

[Notification]
Backend_service_base = ou=services,dc=stoney-cloud,dc=org
People_base = ou=people,dc=stoney-cloud,dc=org
Reseller_base = ou=reseller,dc=stoney-cloud,dc=org
Default_mail_to = support@stoney-cloud.org

[Mail]
Host = mail.tombstone.org
Port = 587
Username = <Sender-Email-Adderss>
Password = verysecret

Graphical Workflow

Figure 1: Workflow for the general notification process

You can modify/update these interactions by editing File:Notification-workflow.xmi (you may need Umbrello UML Modeller diagram programme for KDE to display the content properly).

How to use the Notification.pm module

Given the set up described in section requirements:
Suppose you have the <Service> "notification" and the <Problem> "test". The template referenced in the LDAP (ou=test,ou=templates,uid=<RESELLER>,ou=reseller,ou=configuration,ou=notification,ou=services,dc=stoney-cloud,dc=org) looks like (the notification module uses the perl module Text::Template):

Hello {$name}

This is a notification test from {$hostname}

Cheers
{$writer}

You can now write a very simple perl script which will inform the user and the reseller for the service "notification" and the problem "test". All you need to do is:

  • Use the notification.pm module
  • Create a new instance of the notification class with the following parameters
    • service: "notification"
    • problem: "test"
    • product_uid: <UID>
my $notification = Notification->new( service => "notification", 
                                       problem => "test",
                                       product_uid => $uid,
                                    );
  • Tell the notification module to connect to the LDAP backend
$notification->connectToBackend( $ldap_server,
                                 $ldap_port,
                                 $ldap_bind_dn,
                                 $ldap_bind_pw,
                               );
  • Create the replacement hash
    • As you know the template you can easily fill in the replacement hash
my $replace_hash = {
                      name => "World",
                      hostname => $hostname,
                      writer => "Sysadm",
                   };
  • Finally set the create replacement hash in our notification object and call the notification method
# Set the replace hash for the notification object
$notification->setReplaceHash( $replace_hash );
 
# And notify user and/or reseller
$notification->notify();

As you can see, it is pretty easy to use the notification module if you followed the set up as described in the requirements section.

Error handling

After each method of the notification object, you might want to check whether or not there was an error by calling the error method (for example after connecting to the backend):

$notification->connectToBackend( $ldap_server,
                                 $ldap_port,
                                 $ldap_bind_dn,
                                 $ldap_bind_pw,
                               );
 
# Check if the backup connection could be established
if ( $notification->error() )
{
    # Log what went wrong
    if ( $debug )
    {
        print "Debug: Cannot connect to LDAP server $ldap_server: "
             .$notification->error()."\n";
    }
 
    syslog('err',"Cannot connect to LDAP server $ldap_server: "
                 .$notification->error() );
 }

$notification->error() returns the error message if there was an error. If no error occurred, $notification->error() returns a false value. There is also a method $notification->errorCode() which returns the error code (numeric value).

Source Code

The source code is located in our GitHub Repository:

https://github.com/stepping-stone/notification