Simple FileMaker Server Monitoring

If you’re deploying mission critical FileMaker solutions hosted by FileMaker Server then monitoring the state of your databases and servers is an important part of ensuring everything is running smoothly. Server monitoring is something that’s normally managed by the IT department using dedicated monitoring tools and services to keep an eye on everything, however if you don’t have a dedicated IT department but still need to monitor the uptime of your FileMaker Server databases you will need to implement your own custom monitoring solution.

FileMaker Server has the ability to send email notifications to a nominated email address when errors are logged or when either warnings or errors are logged. However if you’re using web publishing it’s important to note that FileMaker Server sends no email notifications for web publishing errors or warnings. If you need to monitor your web publishing service or would like to do some custom monitoring to check that a particular database is currently hosted then you will need to implement your own monitoring solution.

There’s a number of commercial monitoring services – I’ve used Pingdom and Monitis – which will check for a response from a particular URL and notify you via email/SMS when it encounters an error. You can also tell it what content to expect for a successful result, rather than just relying on a generic HTTP 200 server response. With a bit of PHP code and FileMaker’s PHP API you can quickly setup a custom PHP page to check that the web publishing service is running or that a particular database is currently being hosted, and output a success or error message. You will need to deploy and enable Custom Web Publishing with PHP on your FileMaker Server first, and know where to find the web server root folder on your FileMaker Server machine:

  • on Mac OS X you can find this at /Library/FileMaker Server/HTTPServer/htdocs (or /Library/FileMaker Server/HTTPServer/htdocs/httpsRoot  if you have enabled HTTPS/SSL)
  • on Windows you can find this at [drive]:\Program Files\FileMaker\FileMaker Server\HTTPServer\Conf where [drive] is the drive on which the Web Publishing Engine component of your FileMaker server deployment resides.

Creating the PHP Page:

Using your favourite text editor create a file with the .php extension as follows:

<?php

// Include FileMaker API
require_once ('FileMaker.php');

$fm = new FileMaker();

$fm->setProperty('hostspec', '127.0.0.1'); 

$listDatabases = $fm->listDatabases();

if(FileMaker::isError($listDatabases)) {
 $connectionError = 'Server Error: '. $listDatabases->getMessage(). ' (' . $listDatabases->code . ')';
 echo $connectionError;
} else {
 $connectionError = '';
 echo 'Server Connection Successful';
}

?>

This simply makes a connection to the FileMaker Server (you can change the 127.0.0.1 hostspec address if required) and calls the PHP API listDatabases method – this returns an array of databases that are available with the current server settings and the current user name and password credentials. You will notice that I have not included a FileMaker database Account Name and Password – this will only work when the setting in the FileMaker Server Admin Console List only the databases each user is authorized to access is NOT selected (found under Database Server > Security > File Display Filter).

File Display Filter

We would generally recommend that this is enabled – however this will break our PHP code which will now return an error (401 Unauthorized). We now need to include some account credentials for the database you wish to monitor – I would recommend creating a new Privilege Set/Account in your FileMaker Database just for this purpose with very limited privileges as we won’t be using it to view or create records, but simply to check that the file is being hosted (don’t forget to enable the PHP extended privileges for this Privilege Set).

The PHP code would then look like this (using an Account Name of PHPWeb and Password W3bOnly):

<?php

// Include FileMaker API
require_once ('FileMaker.php');

$fm = new FileMaker();

$fm->setProperty('hostspec', '127.0.0.1'); 
$fm->setProperty('username', 'PHPWeb'); 
$fm->setProperty('password', 'W3bOnly');

$listDatabases = $fm->listDatabases();

if(FileMaker::isError($listDatabases)) {
 $connectionError = 'Server Error: '. $listDatabases->getMessage(). ' (' . $listDatabases->code . ')';
 echo $connectionError;
} else {
 $connectionError = '';
 echo 'Server Connection Successful';
}

?>

If you would like to extend this to check whether a particular database is currently being hosted you can search the array of database names that is returned by the listDatabases method for the presence of a particular file. You can see what the listDatabases array looks like by adding the following line:

echo '<p><pre>'.print_r ($listDatabases).'</pre></p>';

We use the PHP in_array function which checks if a value exists in an array like this:

if (in_array('Contacts', $listDatabases)) {
 echo 'Contacts Database is Live';
} else {
 echo 'Contacts Database is NOT Live';
}

Here I am checking for a database named Contacts – if it is part of the array of databases it will return the string Contacts Database is Live, otherwise it will return Contacts Database is NOT Live.

Here’s the complete PHP code which checks for the individual database name:

<?php

// Include FileMaker API
require_once ('FileMaker.php');

$fm = new FileMaker();

$fm->setProperty('hostspec', '127.0.0.1'); 
$fm->setProperty('username', 'PHPWeb'); 
$fm->setProperty('password', 'W3bOnly');

$listDatabases = $fm->listDatabases();

if(FileMaker::isError($listDatabases)) {
 $connectionError = 'Server Error: '. $listDatabases->getMessage(). ' (' . $listDatabases->code . ')';
 echo $connectionError;
} else {
 $connectionError = '';
 //echo '<p><pre>'.print_r ($listDatabases).'</pre></p>';
 //echo 'Server Connection Successful';
 
 if (in_array('Contacts', $listDatabases)) {
 echo 'Contacts Database is Live';
 } else {
 echo 'Contacts Database is NOT Live';
 }
 
}

?>

N.F. If the Web Publishing Engine is not running on your FileMaker Server deployment you will get a 503 Service Unavailable error.

You can get more information about Custom Web Publishing with PHP from the FileMaker Server 14 Custom Web Publishing Guide.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *