Jump to content

Email Notifications for Network Issues or Outages


sol2010

Recommended Posts

Hi community & hi to my favourite guru  @brian!

Is there a way to provide email notifications to customers when there's a new network issue  (e.g. scheduled server maintenance ?)

I guess this would be set up via a hook, but I have no idea where to start - though I imagine like this:

1) When creating network issue, we can select the "Network Issue Type" & the server name.  I suppose we could perform a check to see which customer has an active instance of that service.

2) For every customer who has an active instance of that service - next thing to do is to check if they ticked a "notify me" box ( I have a checkbox on my registration form, with yes / no data stored as a custom field )

3) If yes to 1 and 2 - then grab their email and send out a notification - ideally with the content of the network issue.

Does anyone have a hook they could share?

Thanks!

 

 

 

 

Link to comment
Share on other sites

4 hours ago, sol2010 said:

Is there a way to provide email notifications to customers when there's a new network issue  (e.g. scheduled server maintenance ?)

there was...

https://marketplace.whmcs.com/product/3078-network-issue-notification

... but it wasn't updated for v8, the Marketplace link no longer works.... and if you go through to their website, you find that they're now a Blesta reseller and don't use WHMCS. wave-smiley.gif

will the last WHMCS developer please remember to turn out the lights when they decide to pack it in too! 💡

you could try contacting them - they may have released it for free or it might still be available and working... off the top of my head, I can't recall any radical changes to network issues in v8.

6 hours ago, sol2010 said:

I guess this would be set up via a hook, but I have no idea where to start

I would expect the NetworkIssueAdd hook point to trigger after an issue has been created in the admin area - that should furnish you with the required information of the issue, e.g in your case, the server ID value.

6 hours ago, sol2010 said:

1) When creating network issue, we can select the "Network Issue Type" & the server name.  I suppose we could perform a check to see which customer has an active instance of that service.

and ensure that a client is only added once to the list - you don't want to be sending multiple emails to the same user just because they have multiple accounts on that server.

7 hours ago, sol2010 said:

2) For every customer who has an active instance of that service - next thing to do is to check if they ticked a "notify me" box ( I have a checkbox on my registration form, with yes / no data stored as a custom field )

that's just a simple SQL query.

7 hours ago, sol2010 said:

3) If yes to 1 and 2 - then grab their email and send out a notification - ideally with the content of the network issue.

2 should give you an array, and then it's a case of looping through it and using the SendEmail API to send the appropriate templated email (product type I assume so you have access to service ID/names etc in the content), to each of them... though i'd be worried if the array was large and you ended up sending a lot of emails (re: spamming or abuse of mail server).

it might be worth having a word with @DennisHermannsen as I can remember a couple of years ago, he was going to write an addon module that does this - whether he ever completed and/or published it, I don't know.... but if he's already started down that road, he might be your quickest option.

Link to comment
Share on other sites

On 6/19/2021 at 1:21 AM, brian! said:

there was...

https://marketplace.whmcs.com/product/3078-network-issue-notification

... but it wasn't updated for v8, the Marketplace link no longer works.... and if you go through to their website, you find that they're now a Blesta reseller and don't use WHMCS. wave-smiley.gif

will the last WHMCS developer please remember to turn out the lights when they decide to pack it in too! 💡

 

Oh that is funny.  Yes, it does feel a bit like that.  Probably all on holiday in Texas with the cpanel folk drinking Paloma cocktails in gold rimmed chalices,  not to mention the $bn yacht.  🙈

Thanks for the tips - I will look further and update this thread if I have any success.

 

Link to comment
Share on other sites

On 6/18/2021 at 3:21 PM, brian! said:

it might be worth having a word with @DennisHermannsen as I can remember a couple of years ago, he was going to write an addon module that does this - whether he ever completed and/or published it, I don't know.... but if he's already started down that road, he might be your quickest option.

I actually did have a working version that would send emails in batches - but I trashed in months ago when we switched from WHMCS' built-in "Network Issues", unfortunately 😕

Link to comment
Share on other sites

3 hours ago, DennisHermannsen said:

I actually did have a working version that would send emails in batches - but I trashed in months ago when we switched from WHMCS' built-in "Network Issues", unfortunately 😕

c'est la via - someone's going to have to reinvent the wheel then... but not either of us! 😎

Link to comment
Share on other sites

  • 1 year later...
On 6/22/2021 at 7:38 PM, DennisHermannsen said:

I actually did have a working version that would send emails in batches - but I trashed in months ago when we switched from WHMCS' built-in "Network Issues", unfortunately 😕

Hi @DennisHermannsen - any chance you could share your previous iteration?

And if you don't mind telling me, what do you mean when you switched?  What did you switch to?

 

 

 

Link to comment
Share on other sites

1 minute ago, sol2010 said:

@leemahoney3

I'd like to ask for your input on this one - if you have a moment ?

Basically if you create a network issue, you want an email notification sent to all clients on the affected server(s) that have it enabled on their account? (eg. custom field checkbox to receive network issue notifications)

What would you want in the email, just a copy of the network issue, or some sort of custom email with a link to the network issue?

Link to comment
Share on other sites

3 minutes ago, leemahoney3 said:

Basically if you create a network issue, you want an email notification sent to all clients on the affected server(s) that have it enabled on their account? (eg. custom field checkbox to receive network issue notifications)

What would you want in the email, just a copy of the network issue, or some sort of custom email with a link to the network issue?

Hi ! Thanks for your swift reply! 

Yes, just something simple:

Subject: Maintenance Notification

Body:

You are receiving this as you have active services...  a, b,c (maybe highlight the service that will be impacted) 

This is to let you know of upcoming maintenance and date:  01-01-2030 

Click here for more [link to issue ] 

 

 

 

Edited by sol2010
Link to comment
Share on other sites

1 hour ago, sol2010 said:

Hi @DennisHermannsen - any chance you could share your previous iteration?

And if you don't mind telling me, what do you mean when you switched?  What did you switch to?

I don't have it, unfortunately. It just grabbed a list of all clients associated with the specific server that had a network issue and send an email to them. That part was very simple and could easily be remade within a few minutes. It's literally just grabbing a list of the clients and use the SendEmail API hook.
IIRC, the tricky part was sending the email in batches. And that was kind of necessary since we would otherwise get a timeout while creating new network issues or updating existing ones. Unfortunately, I don't remember how I send the emails in batches in the background. I probably saved a list of the client's to a custom table and then used the AfterCronJob hook to send emails to a batch of clients.
If you don't really use the Email Marketer feature, you could probably use that one. I don't really know how it works, though.

We switched to Cachet. It's not amazing but it does the job for us. We don't need a fancy status page that can automatically check if a service is down and automatically create an issue if it is. We just need something where we can create a manual network issue.

Link to comment
Share on other sites

Dennis is right, if you've a lot of clients the hook will likely cause a timeout. I've quickly put this together however. 

Basically create a custom field for the clients profile and ensure its of type checkbox. Head over to your database and note the custom field ID as you'll need to input it into the hook.

# Checkbox Custom Field ID
$customFieldID = 8;

1364360206_Screenshot2022-11-03223605.thumb.png.1767eb258f9ef81a8681ad5c5e08a594.png

Next, create a custom email template for the notification, you can assign different custom templates to each notification type (eg. In Progress, Critical, Scheduled) or just use the one for all of them. Set the correct template names in the array in the hook. If you dont want an email sent for a specific status, then leave it blank.

# Enter the custom email template you wish to send when the Network Issue is created with the relevant status.
# Leave the mapping empty if you do not want an email sent if the status matches eg. Outage => '',
# Format is 'status' => 'email-template',

$statusEmailTemplateMappings = [
  'Reported'      => 'New Network Issue',
  'Investigating' => 'New Network Issue',
  'In Progress'   => 'New Network Issue',
  'Outage'        => '', # Left blank so no email is sent
  'Scheduled'     => 'New Network Issue',
  'Resolved'      => '', # Left blank so no email is sent
];

1802376949_Screenshot2022-11-03223853.thumb.png.50875b377545f3f900fbcc58f46583ea.png

1478454068_Screenshot2022-11-03224440.thumb.png.b0c3b21b784b6b2e67fc6bc665d36168.png

The following custom variables are available in the email template:

  • $startdate - The start date and time of the issue
  • $enddate - The end date and time of the issue
  • $title - The title of the network issue
  • $description - The description of the network issue
  • $type - The type of network issue
  • $server - An instance of the Server model
  • $affecting - Not sure on this?
  • $priority - The priority of the network issue
  • $status - The status of the network issue
  • $service - An instance of the Service model

If using $server, I'd run a check to ensure it exists otherwise you'll get an error.  A simple {if $server} ... {else}  ... {/if} will work.

You can also set the service statuses you wish for this to affect, eg. if set to Active and Suspended, only active and suspended services on the related server will be included in the hook.

# Statuses of the services you wish to check
$allowedServiceStatuses = ['Active', 'Suspended'];

Anyways.. here's the full file. Just create a PHP file in /includes/hooks (eg. networkIssueNotificationEmails.php) and paste the code below into it. Make sure to update the variables as mentioned above.

<?php

use WHMCS\Product\Server;
use WHMCS\Service\Service;
use WHMCS\CustomField\CustomFieldValue;

/**
 * Network Issue Notification Emails 
 *
 * @package    WHMCS
 * @author     Lee Mahoney <lee@leemahoney.dev>
 * @copyright  Copyright (c) Lee Mahoney 2022
 * @license    MIT License
 * @version    1.0.0
 * @link       https://leemahoney.dev
 */

if (!defined('WHMCS')) {
    die('You cannot access this file directly.');
}

function network_issue_notification_emails($vars) {

    # Checkbox Custom Field ID
    $customFieldID = 8;

    # Enter the custom email template you wish to send when the Network Issue is created with the relevant status.
    # Leave the mapping empty if you do not want an email sent if the status matches eg. Outage => '',
    # Format is 'status' => 'email-template',
    $statusEmailTemplateMappings = [
        'Reported'      => '',
        'Investigating' => '',
        'In Progress'   => '',
        'Outage'        => '',
        'Scheduled'     => '',
        'Resolved'      => '',
    ];

    # Statuses of the services you wish to check
    $allowedServiceStatuses = ['Active', 'Suspended'];

    /* -------------------------------------------------------------------------------------------------------------------- */

    $server = $vars['server'];
    $status = $vars['status'];

    # Either the status is not listed above or the mapping is empty, stop execution.
    if (!array_key_exists($status, $statusEmailTemplateMappings) || empty($statusEmailTemplateMappings[$status])) {
        return;
    }

    # Otherwise list the active services attached to the server, grab the client and check the custom field for that particular client is "on". If its not, stop execution. Otherwise.. send the email.
    $affectedServices = Service::where('server', $server)->whereIn('domainstatus', $allowedServiceStatuses)->get();

    # Loop through the affected services
    foreach ($affectedServices as $service) {

        # Grab the custom field value for notifications
        $customFieldValue = CustomFieldValue::where(['fieldid' => $customFieldID, 'relid' => $service->client->id])->first();

        # If the client does not have the notification enabled, break out of this loop
        if ($customFieldValue->value != 'on') {
            continue;
        }

        # Otherwise send the email
        $result = localAPI('SendEmail', [
            'messagename'   => $statusEmailTemplateMappings[$status],
            'id'            => $service->client->id,
            'customvars'    => [
                'startdate'     => $vars['startdate'],
                'enddate'       => $vars['enddate'],
                'title'         => $vars['title'],
                'description'   => $vars['description'],
                'type'          => $vars['type'],
                'server'        => Server::where('id', $server)->first(),
                'affecting'     => $vars['affecting'],
                'priority'      => $vars['priority'],
                'status'        => $vars['status'],
                'service'       => $service,
            ],
        ]);

      	# If the email does not send for any reason, log it so we've a paper trail.
        if ($result['result'] != 'success') {
            logActivity("Unable to send network issue notification email, the following error was returned: " . $result['message'], $service->client->id);
        }

    }

}

add_hook('NetworkIssueAdd', 1, 'network_issue_notification_emails');

 

Edited by leemahoney3
Link to comment
Share on other sites

Wow - that's fantastic.  I will definitely test this and provide feedback.   I am copying this to Github channel so that it remains available , in case of changes on this community etc?

https://github.com/solaceten/WHMCS-Hooks/blob/main/includes/hooks/maintenance-notification-email

I'll report back when I've had a chance to test - meanwhile, the only improvement I can see straight away would be:

How to have an option to send to all customers, without checking for a specific server?  WHMCS does not allow us to select multiple server names when creating a network issue, so to save time (and not have to duplicate a general notification across multiple instances) we usually just create one network issue and assign it to "System "  - then in the title, we add in "All servers". 

Could we have an option for - "If system > then send to all"  -  assuming they are an active client !

 

Link to comment
Share on other sites

11 minutes ago, sol2010 said:

Wow - that's fantastic.  I will definitely test this and provide feedback.   I am copying this to Github channel so that it remains available , in case of changes on this community etc?

https://github.com/solaceten/WHMCS-Hooks/blob/main/includes/hooks/maintenance-notification-email

I'll report back when I've had a chance to test - meanwhile, the only improvement I can see straight away would be:

How to have an option to send to all customers, without checking for a specific server?  WHMCS does not allow us to select multiple server names when creating a network issue, so to save time (and not have to duplicate a general notification across multiple instances) we usually just create one network issue and assign it to "System "  - then in the title, we add in "All servers". 

Could we have an option for - "If system > then send to all"  -  assuming they are an active client !

 

I believe if you choose System, it will send it out to all clients that have active or suspended services, open to correction though if you'd like to test it and see!

Link to comment
Share on other sites

You would actually be able to use the Email Campaign (not Email Marketer) feature. You're able to set a specific server (or select all servers).

The email marketer sends out emails in batches when the WHMCS cron runs. Only issue is that it only sends 25 emails per time the cron job runs (or per minute, the documentation is a bit vague on that point).

Link to comment
Share on other sites

9 hours ago, DennisHermannsen said:

You would actually be able to use the Email Campaign (not Email Marketer) feature. You're able to set a specific server (or select all servers).

The email marketer sends out emails in batches when the WHMCS cron runs. Only issue is that it only sends 25 emails per time the cron job runs (or per minute, the documentation is a bit vague on that point).

Thanks DennisHermannsen  - I'm not sure if you are answering me, or @leemahoney3 in regards to his code suggestion.

From my point of view, I simply want to post a notification on the network issue page (e.g. upcoming maintenance) and when I hit 'Save / Post' I want it to do the rest for me (inform users). 

TBH this should be a core feature of the software.  I mean, a product that actually purports to be a Web Host Manager Complete Solution, should be able to inform customers when their web hosting solution is going to be out of action - e.g. when a notice is published.....  give us the ability to tick a box 'Send notification?'   What do you say @WHMCS John  - Actually, I know what you'll say....  but the feature request section is not a solution, it's a graveyard of sensible ideas.

😵

 

 

Edited by sol2010
Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated