Configure Zabbix Alert Scripts

zabbix alert scripts banner

Steps:

 

  • Create Jabber Script
  • Test from terminal
  • Configure Zabbix to use Jabber script
  • Create Email Script
  • Test from terminal
  • Configure Zabbix to use phpmailer script
  • Tell Zabbix to notify
  • Flap a server to verify operation

jabber.sh is a replacement for the built-in Jabber/XMPP functionality within Zabbix.  You may need to install ‘sendxmpp’ prior to installation.  This is functional in an Ubuntu Xenial server installation, but the path may vary for CentOS/RHEL deployments.

Contents of /usr/lib/zabbix/alertscripts/jabber.sh:


#!/bin/bash
to=$1
body=$2


cat < $2
EOF

 

Adjust ‘user’, ‘server’ and ‘password’ accordingly for your particular setup.  The script should be owned by the zabbix user and have execute permissions set:

-rwxr-xr-x 1 zabbix root 288 Jun 16 05:11 jabber.sh

To test, simply execute the script like any other. Note the arguments passed into it:

# /usr/lib/zabbix/alertscripts/jabber.sh recipient@server message

If unable to send, try using sendxmpp outside the script and make sure it can send that way, then debug the script as required.

Your Zabbix should look like this:

 

zabbix setup 1

zabbix alert scripts screenshot 2

Note that the ‘Type’ of the media for the user corresponds to the name of the script we added earlier.

Email follows a similar procedure. Just make sure to have the necessary PHP modules installed. Below is the setup to use a gmail account:

Contents of /usr/lib/zabbix/alertscripts/phpmailer.php:


#!/usr/bin/php
require_once "Mail.php";


$from = "ZABBIX <user@domain>";
$to = $argv[1];
$subject = $argv[2];
$body = $argv[3];


$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "username";
$password = "password";


$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));


$mail = $smtp->send($to, $headers, $body);


?>

Adjust ‘user’, ‘server’ and ‘password’ accordingly for your particular setup. The script should be owned by the zabbix user and have execute permissions set:

-rwxr-xr-x 1 zabbix root 572 Jun 16 12:26 phpmailer.php

To test, simply execute the script like any other. Note the arguments passed into it:

# /usr/lib/zabbix/alertscripts/phpmailer.php user@domain.tld subject body

Make Zabbix look like this:

zabbix-4

 

Note that the ‘Type’ of the media for the user corresponds to the name of the script we added earlier.

zabbix screenshot 5

Most important step!  This tells zabbix to actually use everything we just set up.  Once this is enabled, flap a server to give zabbix something to tell you about.  Check Pidgin and your email to see if it worked! :)

 

 

 

Magento: Importing CSVs

magento csv import article banner image

Importing products into Magento with a .csv file can be an incredibly time consuming and sometimes frustrating experience. One can be faced with one hundred columns of product attributes, only some of which seem to match up with the product information that you have on hand. However, uploading via .csv is the best option for uploading multiple products in one batch, and can be made a little easier by following a process and having a little understanding of how to match the cryptic information seen on a magento excel sheet with what you’re seeing or want to see on the front end of your website.

Mandatory Attributes:
When you’re uploading products to Magento, not every variable that is listed in your exported template is necessary to fill out (or include at all). However, in order to successfully upload a .csv, you’ll need to include the mandatory attributes. These include attributes that are, by default, mandatory for any Magento product, as well as attributes that are mandatory to your site exclusively, according to its design and specific needs. If you are only uploading the minimum mandatory fields for products that don’t yet exist, you will need to upload further further information before the products are live.

Magento’s mandatory attributes are:
sku
_attribute_set
_type
price
name
status
visibility
description
tax_class_id
short_description
weight

These attributes are listed in their “attribute code” form as they will appear on a spreadsheet for Magento. Even if some of these field have been altered by site developers, the majority will be mandatory on any Magento site:

sku – your products’ unique alphanumeric identifier.

_attribute_set – refers to a default attribute set that each type of product has. for example “shoes” _attribute_set would likely include a single number representing shoe size and color attribute, whereas “pants” _attribute_set would automatically include a number for both waist and inseam as well as color. _attribute_set defines the attributes that apply to categories of products.
Attribute sets will be defined by the sites developers, so they will vary from site to site, and it’s best to speak with the person who set them up in order to get a good grasp of what they are on your site.

_type – refers to whether your product is simple or configurable. In other words whether it is a stand alone product, a variation, or the parent of variations
price – Self explanatory, the price of the products

name – The title of your product

status – whether or not the product is active on the website. Shown in the back end product page as “Enabled” or “Disabled,” and represented in a .csv by a 1 (enabled) or 2 (disabled)

visibility – Refers to visibility of product on site: Search and Catalog. Most simple products that belong to a parent configurable will not be visible individually. Represented numerically in a .csv.

description – Self explanatory, this is a text field for you to enter a product description. Where this appears on the front end of your site depends on its design.
Note- this field can be changed to non-mandatory by site developers

tax_class_id – Refers to what, if any, taxes will be applied to your products. Found in a dropdown menu under “Price” on the Manage Product page and represented numerically in a .csv. Refer to below tip to find out numerical values associated with dropdown menues

short_description – Similar to description, this text field will display in different ways depending on your site’s design. Also, like description, short_description can me made not mandatory by site developers.

weight – self explanatory. Like other fields, if it has no bearing on your site’s business you can enter a dummy number in order to successfully upload files.
TIP – For variables with numerical values, there’s a relatively simple way to “cheat” and find out what number is associated with each option. Using Chrome, Firebug, or any other application that allows you to view the page source:

  • Find the field in the magento product page
  • Select the variable field (dropdown or text) and inspect the source code – the values and their associated options will be displayed

magento attribute code source code inspection

 

Best practice for uploading products via CSV:

1) Export a representative of each Type of product to use as a template.

If you do not already have products uploaded to your site, manually add a product of each type and make sure that they are all displaying correctly on the front end.

The most important part of exporting a .csv that will be useful to you as a template is that you export one representative of type of product that will be carried on your site. The most important variations will be type–simple or configurable–and _attribute_set–defined by your site developers.

It’s important to briefly define Simple and Configurable products as understanding their relationship and different characteristics has an impact on the necessary fields in an import:

Configurable Products: Configurable products represent the “face” of a product that exists in different variations. On ecommerce sites these variations will most often be “size,” “color,” or other such variations. The configurable product is what will show on a website’s front end, allowing consumers to add simple products that have been associated with the configurable product to their cart. Examples of fields that may be required of configurable but not simple products are: associated products, multiple images, product descriptions, and much more.

Simple Products: A simple product will be created for each variation of a configurable product. For example, if you are selling a shirt that comes in three different sizes, you will upload three individual simple products in addition to the configurable product. Fields such as weight, price, and others that are dependent on which variation a consumer chooses may be required of simple products where they are left blank on a configurable.

Due to these differences, it’s very important that you find a representative of each type of product so that later you can see the differences on a magento .csv.

Once you have found the products that represent everything in your catalog, you’ll export your .csv which will give you all the information under attribute code column titles (for identifying attribute codes see below).

This is done through System > Import/Export > Export.

magento csv export navigation

 

Select Products:

export magento csv screenshot

Note – the simplest way to pull out your sample products for a template is simply to download all existing products and copy and paste your selected samples onto a new template page. However, if you have identified the products that you want for your template, you can limit your export to only the products you want by checkboxing them ( search by sku, name, etc.).

See example:

select attributes for export magento screenshot

 

To export click Continue at the bottom-right of the page and open the .csv file in Excel or Google Sheets.

2) Create your template:

When you are faced with the full range of data that is exported by Magento for each product it can be incredibly difficult to view easily. In this case using the Hide Columns feature for attributes that are non mandatory and are not necessary for the information you’re uploading is a massive help.

If the spreadsheet is being filled out by a client for you to upload, providing them with a clear template such as this will simplify the upload process for both parties.

If you are only updating a small number of attributes for many products, you can actually delete all but the mandatory columns, leaving you with a much cleaner spreadsheet.

3) Enter one product from each category into your spreadsheet for a trial upload:

One thing that you want to avoid is spending hours on entering your entire catalog into an excel sheet only to find that you’ve made a mistake and need to go through the entire thing and modify every product. For this reason it’s worth your time to experiment with an upload.

At this point you should have a list of several products, with the unnecessary columns either hidden or deleted for simplicity. When adding to an excel sheet for upload pay close attention to detail:

  • fill out fields in the exact format that your example has shown.
  • pay attention that you do not include any spaces in your entries – it’s particularly easy to accidentally add a space at the end of an entry when copying and pasting.
  • Use caution when using search and replace. Although using spreadsheet shortcuts is a massive help when creating a .csv you need to exercise caution. Never forget about hidden columns.

Once you’ve filled out your sample spreadsheet, you’re able to check the data for errors. After this, you’ll upload. This is a fairly simple process: Go to  System > Imports / Exports > Import. Select “products” just like when exporting, and choose file (be sure that your spreadsheet is saved in .csv).

Note- Occasionally you may run into issues if you save your spreadsheet with MS Excel due to its unique encoding. As a result, some recommend using an alternative to Excel to avoid a possible error after completing your sheet.

If you’re lucky, you’ve encountered no errors and your products have been successfully uploaded however, more likely, you’ll get a screen like the following:

magento import error screenshot

As can be seen here Magento gives you an attribute code (meta_description in this case) followed by the lines on which it was entered incorrectly (or not at all). In this case “invalid value” tells us that it was an error with the format that we entered.

If the error messages do not specify rows you can often inspect the source code of the error message to identify the row with an error.

Just because Magento accepts your spreadsheet does not mean that everything is correct. Be sure to check how your products are appearing on the front end, particularly images, text, and any other information that is may be entered in several different attribute columns in the same format.

When you encounter errors, some of the attribute codes will make sense to you, but others may be a bit vague, and in this case it’s useful to know how to find what the attribute code represents in the backend of your site:

To Identify an Attribute Code (Or the column title on exported excel sheet)

Assuming that you did not develop the Magento site yourself (or even if you did) the column headers on your exported Excel sheet can be cryptic at times, making it hard to know what, if any, information you should enter into the column.

To identify an attribute code:

  • Copy the attribute code (column header) and paste it into Attributes in the Magento Back end.
    • To do this, navigate from the menu bar: Catalog > Attributes > Manage Attributes:

manage attributes magento screenshot

  • Once in Manage Attributes, paste the attribute code into the left-hand “Attribute Code” search box:

magento attribute codes screenshot

  • The “Attribute Label” is listed to the right of your search results, and is also displayed when you click into a specific attribute’s details. In most cases this should be enough to understand the Attribute that the code refers to. For more information, you can look at a specific product in the back end (Catalog > Manage Products > Select a product) to see if and how the attribute has been filled out for the pre existing product.
  • Many titles and section headings on front end product pages will directly correspond to their Attribute Label in the back end. Thus you can reverse this process by finding the field you’re looking for on the front end and finding the Attribute Code that corresponds to the Attribute Label, allowing you to find the appropriate column on your spreadsheet.

 

4) Upload your entire .csv

After you’ve uploaded a sample and identified any errors, you’ll go ahead and fill out all of your products for upload.

Most Common Errors- 

Incorrect Case Entry- Entering headers or fields in a case that does not match that of your export is an easy mistake that will cause Magento to be unable to upload. These can occur in unexpected places such as file extensions depending on the setup of your site.

Incorrect Column Headers – As with everything in the .csv upload process, there is no room for error in your variable names. Make sure that your upload .csv has exactly the same field names as the sample that you exported, paying particular attention to capitalization, spacing, and underscores.

Incorrect CSV File Encoding –  As mentioned before, this can be due to the program you’re using to save your .csv but can also be a result of differences in location (countries). Be sure that you’re using Unicode UTF-8 when you’re saving your file as this is the only format that Magento will accept.

Incorrect Characters – Some fields may use html code, in which case you’ll need to be sure that you don’t have characters that require special code (for example “<”).

Image Import Errors – Make sure that all of your images are uploaded to the /media/import folder and that your spreadsheet image names are identical to the names in the media folder.

 

Using URL Builder to Improve Analytics Reporting

When using Analytics, Google itself has access to enough information to feed you a lot of data in terms of users’ interactions with your website, as well as where they originated from. However, there are a couple types of marketing efforts efforts that can lead to users accessing your site from sources that Google either can’t identify or can’t segment enough to be useful to you.

The two prominent examples are email marketing campaigns and running multiple ads on a single domain. In the case of email campaigns, google doesn’t have control over your email client, and thus doesn’t know where the email link originated. As a result, without using URL builder, one’s email campaign traffic will likely end up showing up under Acquisition Channels as Direct traffic. When running multiple ads on one website– you may have one banner ad, header, footer, plain text, etc.– google will not be able to differentiate which traffic came from which ad, preventing you from assessing their performance and adjusting accordingly.

In these cases, Google offers a simple tool to feed it the information it needs in order to give you this useful data- URL builder. Using URL builder allows you to create a custom url for your destination page and attribute the desired source information, in turn allowing Google Analytics to better display the exact behavior of users.

 

To access URL Builder click here or search for “URL builder” and ,if you’re logged into analytics, you should see a page like the following:

 

URL builder homepage

 

Taking the example of an email marketing campaign, what you’ll want to do is enter the url of the page that you are linking to in your emails. In this case lets say that I’m sending links to Astral Web’s content page:

 

URL Builder Landing page

I then fill out the boxes as required below:

URL Builder Demonstration image

*when copying and pasting destination URLs, be sure that they do not contain any excess coding or characters- you’ll end up with a non-functional link.

After clicking Submit, we’re given a long link that includes all of the information that has just been entered into URL Builder.

Unique URL from URL builder

This is the link that I’ll want to put into my emails (or ads, etc.) in order to identify them in analytics.

In order to ensure that the link is functional and visible in analytics, paste this link into a separate browser window while you’ve got your viewing your Real Time > Traffic Sources. As you can see below, if the link is functioning properly, you’ll be able to see it almost immediately in Analytics. Furthermore, all the information you’ve input to distinguish the medium, campaign, and target are now identified by Google, and Analytics can give you the kind of information that is really crucial to optimizing your marketing campaigns.

Checking URL builder with Real Time view

If you’d like more information, please check out Ori’s video tutorial on using URL Builder.

 

Installing WordPress (quick guide)

Here’s a straight-forward step by step guide on how to Install WordPress 3.6/3.7

We are always happy to answer any questions you may have. Let’s begin!

Install WordPress on Server

Step 1: Download WordPress

Go to wordpress.org and click on download to get the latest wordpress files.

Download WordPress

Step 2: Upload WordPress to Server

Use your favorite FTP client to upload the files to your server. If you have downloaded a compress file, you’ll have to unzip it.

Upload Files to FTP

Step 3: Setup MYSQL Database

Go to your hosting database section and add a new database. Don’t forget to write down your login information.
* username, password, database name, hostname

Setup Mysql Database

Step 4: Define Connection information for WordPress

Go to your server via your FTP client and edit your wp-config-sample.php file. Replace file with your username, password, database name and hostname.

After you have completed filling up information, rename the file to wp-config.php

Input Database Information

Step 5: Start Installing from browser

Go to your browser and visit the url of server you have placed wordpress on.

You will arrive to a setup screen. Fill out all information and don’t forget your username and password.

Install WordPress

Step 6: Login to Site and Test Site Live

Login to backend and view frontend to test site.

Login to WordPress Admin Area

Wordpress Admin Area

Test WordPress Site for First Time

You’re awesome! You made it!!!


Setup Theme:

Step 1: Login to Admin

Login to site.com/wp-admin/ on server.

Wordpress Admin Area

Option A – Install from wordpress existing theme

Step 2: Go to theme section

Go to appearance -> themes -> install themes

Install Theme

Step 3: Preview, Select and Install

Search for the desired theme and once you preview and are happy click on the install link and approve.

Preview Theme

Step 4: View Live site

Go to main site and confirm that theme looks good.

Test New WordPress Theme

OPTION B: Get a theme from external source (free, paid)

Step 3: Upload to Server

Go to FTP -> /wp-content/themes/ and upload theme folder

Upload Theme Via FTP

Step 4: Activate in Themes Section

Go to Admin -> Appearance -> Themes -> Manage Themes -> Available Themes and “activate”

Activate Theme

Step 5: View Live site

Go to main site and confirm that theme looks good.

Test New Theme

Simple Password Protect Category Pages

Using htaccess, godaddy, php, cgi fix, $_SERVER[‘PHP_AUTH_USER’], $_SERVER[‘PHP_AUTH_PW’]

Fixes:
godaddy login keeps on popping up (popup) due to cgi mode.

Works on Specific Categories


See code fix:

1. PHP FILE


$pageurl=$_SERVER[REQUEST_URI];

if(($pageurl=='/categories/x')||($pageurl=='/categories/y')){

if(isset($_SERVER['HTTP_AUTHORIZATION'])) {
$auth_params = explode(":" , base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
$_SERVER['PHP_AUTH_USER'] = $auth_params[0];
unset($auth_params[0]);
$_SERVER['PHP_AUTH_PW'] = implode('',$auth_params);
}

if (!isset($_SERVER['PHP_AUTH_USER'])) {
header("WWW-Authenticate: Basic realm="Private Area"");
header("HTTP/1.0 401 Unauthorized");
print "Sorry - you need valid credentials to be granted access! Try again by refreshing this page. Refresh Pagen";
exit;
} else {
if (($_SERVER['PHP_AUTH_USER'] == 'username') && ($_SERVER['PHP_AUTH_PW'] == 'password')) {

} else {
header("WWW-Authenticate: Basic realm="Private Area2"");
header("HTTP/1.0 401 Unauthorized");
print "Sorry - you need valid credentials to be granted access! Try again by refreshing this page. Refresh Pagen";
exit;
}
}
}

2. HTACCESS (linux)


RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]