Logaholic Cloud Manager and API

The Logaholic Cloud Manager allows you to bundle multiple Logaholic installations (on the same or on multiple servers) into a “cloud” of servers which you can manage as a single Logaholic installation. This allows you to create centralized management of Logaholic accounts, profiles and subscriptions for hundreds of thousands of users.

The API for Logaholic Cloud Manager provides a framework that allows you to integrate Logaholic server, user, profile and subscription management features into your existing back-end systems.

The API has the following features:

  • Add and Edit servers (Logaholic installations)
  • Add, Edit and Delete user accounts
  • Add, Edit and Delete website profiles
  • Synchronize your subscriptions

Contents

Install Logaholic Cloud Manager

To install the Logaholic Cloud Manager, simply copy the contents of the www folder from your download file to a web accessible location on your server.

Next open a browser and navigate to the install.php file, for example:

http://localhost/cloud_manager/install.php

Follow the steps on the screen.

Next, go to Global Settings and click “Enable Cloud Manager” and provide the information requested.

This Logaholic installation is now ready to act as the Cloud Manager UI.

Install Cloud API

1. To install the Logaholic Cloud API, simply copy the cloud_api folder from your download file to a location on your server.

* If you want to be able to access the API’s functions via HTTP requests, place the “cloud_api” folder in a web accessible directory.

* If you only want command line access to the API’s functions, choose an non web accessible location on your server and ensure the api folder has the appropriate permission levels.

2. Open the following file in an editor and enter the appropriate values.

/cloud_api/config-example.php

Make sure that when you are done editing the file to rename config-example.php to config.php

Enter the full absolute system path to the folder that Logaholic is located in
$config[‘path’] = “/var/www/vhosts/domain.com/httpdocs/cloud“;

The values in red above are examples and should be replaced with your actual values.

The $config[‘path’] variable above should point to the main Logaholic Web Analytics folder, not the directory where you put the API files

That’s it. You are now ready to use the API for server management tasks.

Using the API

In the examples below, we’ll pretend the Logaholic Cloud Manager API files are installed in /var/www/cloud_api and can be reached via “http://localhost/cloud_api”.

When accessing the API via HTTP, requests should look something like this:

http://localhost/cloud_api/index.php?action=action&key=val&key=val

When accessing the API via the command line shell, commands should look something like this:

cd /var/www/cloud_api; php index.php “action=action&key=val&key=val”

Possible values for action and other key/value pairs will be described below. For the sake of simplicity, we’ll only provide examples of HTTP requests below, but these can all be transformed into the command line equivalents using the example above.

Parameter values containing special characters (like ‘&’) should be urlencoded in the API request

The API always returns json encoded data as output that contains if it succeeded or not and for which installation the call was made.
Examples:

{“Succes”:[“Success: Added user test”],”Installation”:”Test”}

{“Error”:[“An error occurred: Duplicate entry ‘test’,”Installation”:”Test”}

Adding Servers

To connect a Logaholic to your cloud system, you’ll need to make a request using the following parameters:

Parameter Value Notes
action addserver Tells the API we want to add a server
install_name string Give your Logaholic installation a name (this is used as an identifier).
install_url string The url to the Logaholic Installation you want to connect with
server_api_password string The API password of the installation
server_api_path string For local installs (hosted on the same machine as the Cloud manager) provide the absolute path to the API of the installation. For remote installs (logaholic installation hosted on a different physical server) provide the HTTP address to the remote cloud API

A simple API request to add an installation could look like this:

http://localhost/cloud_api/index.php?action=addserver&install_name=Test&install_url=http%3A%2F%2Flocalhost%2Flogaholic_1%2F&server_api_password=test&server_api_path=%2Fvar%2Flogaholic_api_1%2F

Editing Servers

To edit a Logaholic connection, you’ll need to make a request using the following parameters:

Parameter Value Notes
action editserver Tells the API we want to edit a server
edit_install_name string This is the name of the installation you want to edit.
install_name string Give your Logaholic installation a name (this is used as an identifier).
install_url string The url to the Logaholic Installation you want to connect with
server_api_password string The API password of the installation
server_api_path string For local installs (hosted on the same machine as the Cloud manager) provide the absolute path to the API of the installation. For remote installs (logaholic installation hosted on a different physical server) provide the HTTP address to the remote cloud API

A simple API request to edit an installation could look like this:

http://localhost/cloud_api/index.php?action=editserver&edit_install_name=Test&install_name=TestNewName&install_url=http%3A%2F%2Flocalhost%2Flogaholic_1%2F&server_api_password=test&server_api_path=%2Fvar%2Flogaholic_api_1%2F

Deleting Servers

To delete a Logaholic connection, you’ll need to make a request using the following parameters:

Parameter Value Notes
action removeserver Tells the API we want to remove a server
install_name string Give the Logaholic installation name you want to delete.

A simple API request to delete an installation could look like this:

http://localhost/cloud_api/index.php?action=removeserver&install_name=Test

Selecting the best Server Automatically

The Logaholic Cloud Api accepts the parameter install_name with all the user/profile requests to define which installation the action must be completed for.
If there is no install_name given with the request; The system chooses the best installation for you. This is done by selecting the installation with the least amount of profiles.

Adding Users

To add users to your logaholic system, you’ll need to make a request using the following parameters:

Parameter Value Notes
action adduser Tells the API we want to add a user
username string – Any alphanumeric string up to 100 characters length
password string Any md5 of your password.
Optionally, you can add the following parameters:
fullname string – The users full name, e.g. John Doe
– Any alphanumeric string up to 100 characters length
email string – The users email address
– Any alphanumeric string up to 100 characters length
accessEditProfile 0 or 1 – Controls whether the user can Edit certain profile settings
– 0 = No, 1 = Yes
– Default 1
accessAddProfile 0 or 1 – Controls whether the user can add new profiles from the Logaholic UI
– 0 = No, 1 = Yes
– Default 0
accessUpdateLogs 0 or 1 – Controls whether the user can manually Update statistics from the Logaholic UI
– 0 = No, 1 = Yes
– Default 0
active 0 or 1 – Controls whether the user account is active and can log in
– 0 = No, 1 = Yes
– Default 1
expires 0 or timestamp – Controls whether the user account expires at a certain point in time. If left to ‘0’, the account never expires. Otherwise, it expires when the unix timestamp value is met.
– Default 0
subscriptionid int – The id of the subscription you want to add to the user.
– Default 0
subscriptionname string – The name of the subscription you want to add to the user.
– Default ”
install_name string – With this you can tell the api to add the user to a specific installation

A simple API request to add a user could look like this:

http://localhost/cloud_api/index.php?action=adduser&username=michael&password=mypass

If the operation is successful the script will return the following string:

{“Succes”:[“Success: Added user michael”],”Installation”:”Test”}

If the request fails, it will output an error message.

Users added through the API are always non-admin users. This means they can only access profiles they own and cannot edit certain profile settings (like profile name and data collection method), even if accessEditProfile = 1

Editing Users

To Edit a Logaholic user account with the API, you can follow the instructions for adding users above, with these exceptions:

Parameter Value Notes
action edituser Tells the API we want to edit a user
new_username string – Any alphanumeric string up to 100 characters length
– This can be the same as the original username, or a different string, but the parameter must be present

A simple API request to edit a user could look like this:

http://localhost/cloud_api/index.php?action=edituser&username=michael&password=myNEWpass&new_username=michael

If the operation is successful the script will return the following string:

{“Succes”:[“Edited User michael\n”],”Installation”:”Test”}

If the request fails, it will output an error message.

Deleting Users

To delete a user account, use the following parameters:

Parameter Value Notes
action deleteuser Tells the API we want to delete a user
username string The username of the user you want to delete

A simple API request to delete a user could look like this:

http://localhost/cloud_api/index.php?action=deleteuser&username=michael

If the operation is successful the script will return the following string:

{“Succes”:[“Removed user michael”],”Installation”:”Test”}

If the request fails, it will output an error message.

Warning: Deleting a user will also delete any website profiles that belong to that user!!!

Adding Profiles

When adding a website profile to Logaholic through the API, it’s important to note the following:

* If no profile name is given, the API automatically generated a profile name based on the site’s (sub) domain. For example, adding a profile for www.test-me.com, would generate a profile name called ‘wwwtestmecom’.

* Using the API only a limited number of profile settings can be set. Other settings must be changed via the regular UI.

* When a log file location is not provided, we assume the profile will be using javscript tags to collect data.

To add a website profile via the API, you can use the following parameters:

Parameter Value Notes
action addprofile Tells the API we want to add a profile
username string – The username of the account that owns this site
– The username must exist, so always add users before adding profiles
site string Any (sub)domain, e.g. www.mysite.com
Optionally, you can add the following parameters:
profile_name string – The name you want to give this profile in the logaholic system
– If this parameter is missing, the profile name is automatically derived from the site parameter
logfilelocation string – The system path to the log file or the directory that contains the log files for this site
– If this parameter is missing, the profile is set up to use Javascript data collection
splitlogs 0 or 1 – Indicates whether the logfilelocation parameter points to a single log file, or to a directory containing multiple log files
– 0 = Single file, 1 = Directory (multiple files)
– Default 1
splitfilter string or (regular expression) This parameter can be used to avoid unwanted files in the directory to be analyzed. For example, if all your log file names start with “access_log”, use that as the value for this parameter. Only files that (partially) match this value will be analyzed. Leave this blank if all files in the logfilelocation directory need to be analyzed. If you require more complex filtering capabilities, you may also enter a regular expression, between parenthesis. For example (^www\.[xyz|abc.xyz].log.*)
activated 0 or 1 – Use this option to activate an profile. (1 = active or 0 = not active)
– default 0

An API request to add a profile could look like this:

http://localhost/cloud_api/index.php?action=addprofile&username=michael&site=www.test-me.com&logfilelocation=/var/www/vhosts/mysite.com/logs/

If the operation is successful, the script will return the following string:

{“Succes”:[“Created profile wwwtestmecom for www.test-me.com \n”],”Installation”:”Test”}

If the request fails, it will output an error message.

Editing Profiles

To edit a website profile via the API, you can use the following parameters:

Parameter Value Notes
action editprofile Tells the API we want to edit a profile
username string – The username of the account that owns this site
– The username must exist, so always add users before adding profiles
site string Any (sub)domain, e.g. www.mysite.com
Optionally, you can add the following parameters:
profile_name string – The name you want to give this profile in the logaholic system
– If this parameter is missing, the profile name is automatically derived from the site parameter
logfilelocation string – The system path to the log file or the directory that contains the log files for this site
– If this parameter is missing, the profile is set up to use Javascript data collection
splitlogs 0 or 1 – Indicates whether the logfilelocation parameter points to a single log file, or to a directory containing multiple log files
– 0 = Single file, 1 = Directory (multiple files)
– Default 1
splitfilter string or (regular expression) This parameter can be used to avoid unwanted files in the directory to be analyzed. For example, if all your log file names start with “access_log”, use that as the value for this parameter. Only files that (partially) match this value will be analyzed. Leave this blank if all files in the logfilelocation directory need to be analyzed. If you require more complex filtering capabilities, you may also enter a regular expression, between parenthesis. For example (^www\.[xyz|abc.xyz].log.*)
activated 0 or 1 – Use this option to activate an profile. (1 = active or 0 = not active)
– default 0

An API request to add a profile could look like this:

http://localhost/cloud_api/index.php?action=editprofile&username=michael&site=www.test-me.com&logfilelocation=/var/www/vhosts/mysite.com/logs/

If the operation is successful, the script will return the following string:

{“Succes”:[“Edited Profile www.test-me.com.”],”Installation”:”Test”}

If the request fails, it will output an error message.

Deleting Profiles

To delete a profile from the logaholic system, you can use the following parameters:

Parameter Value Notes
action deleteprofile Tells the API we want to delete a profile
username string – The username of the account that owns this site
– The username must exist, or the profile will not be deleted
site string The (sub)domain you want to delete the Logaholic profile for

An API request to delete a profile could look like this:

http://localhost/cloud_api/index.php?action=deleteprofile&username=michael&site=www.test-me.com

If the operation is successful the script will return the following string:

{“Succes”:[“Deleted Profile www.test-me.com”],”Installation”:”Test”}

If the request fails, it will output an error message.

Synchronize Subscriptions

Within Logaholic you can create subscriptions for your users. To be able to share your subscriptions with your other Logaholic installations we added this option to do so.

To use this you first need to have created a subscription on one of your installations.
Click here for more information.

To synchronize subscriptions over your logaholic systems, you can use the following parameters:

Parameter Value Notes
action syncsubscription Tells the API we want to synchronize subscriptions
install_name string – Select the source installation from you wish to synchronize the subscription packages.
Optionally, you can add the following parameters:
include array – Select the installations you wish to synchronize the subscriptions to. ( if this is not set it synchronizes to all installations )

For the next example we say we have three installations and we want to synchronize the subscriptions from ‘Test’ to the other installations.

An API request to synchronize the subscriptions could look like this:

http://localhost/cloud_api/index.php?action=syncsubscription&install_name=Test

If the operation is successful the script will return the following string:

{“Succes”:[“Synchronized subscriptions”],”Installation”:”Test”}

If the request fails, it will output an error message.

Direct Login / Request Login Url

With the Logaholic Cloud Manager you have multiple installation and you want to give your users a quick login url without searching for it.
The api provides two actions to let your user login:

  • login - This action redirects and logs the user directly into Logaholic.
  • loginurl - This action only returns the login url for the selected user to log into the correct Logaholic installation.

To successfully use these actions the api accepts the two following parameter methods:

  • username + password - Use the username and password parameters to make a successful request.

  • http://localhost/cloud_api/index.php?action=loginurl&username=michael&password=mypass

  • lgpkey - You can also use the lgpkey directly to request a login/loginurl ( Click here for 'lgpkey' information).

  • http://localhost/cloud_api/index.php?action=loginurl&lgpkey=hash:hash

Keeping the cloud up to date

The Logaholic Cloud Manager keeps user and profile data local to be able give you a fast overview and api result. But if there are changes made in an installation without using the Cloud Api then the Cloud Manager could be wrong or incomplete from that moment.

The “cloudCron.php” command line script allows you to automatically keep the Cloud Manager up to date. The script is located in the following directory:

cloud_api/cloudCron-example.php


Edit the script to add an path to your Cloud Manager installation.


Rename the cloudCron-example.php script to cloudCron.php to use it.

This script can only be started from the command line and will update the data in your Cloud Manager.

Usage:

php -q cloudCron.php

Example: In a scheduled cron job, this command can be set up to run every hour at minute 55 like this:

55 * * * * cd /path_to_your_logaholic_cloud_api/;php -q cloudCron.php

When running on Windows, edit the script to point to the correct location (path) for your PHP executable (e.g., C:\PHP\php-cgi.exe)