Share script through multiple monitors

Our team supports multiple environments with the same logic. So, we need to monitor all of environment.
We have implemented script for ping login screen. And we do not want to Copy&Paste this script for every monitor per environment(the only one difference - environment URL). Is there possibility to share a single script through several monitors? If yes, how can it be parameterized?

Hi @vsvyst - It might be possible to use the Synthetic API to automate the creations of the scripts using your own scripting language to generate these.

Hi, @vsvyst: One of our customers came up with a clever solution to this problem: Save the reusable script in a Github gist, then retrieve and execute it within your Synthetics monitor. For example:

var scriptUrl = '<username>/<gist-id>/raw/filename.js';

  .then(function() {
    return $browser.findElement($driver.By.css('body > pre'));
  .then(function(element) {
    return element.getText()
      .then(function(script) {
        var envUrl = 'https://...';
        var login = new Function('$browser', '$driver', 'envUrl', script);
        return login($browser, $driver, envUrl);

Would this workaround method work for API scripted monitors as well?

Hi, @annnovakowski: It should work, but you will have to do $http.get() instead of $browser.get(). And you won’t be able to do $browser.findElement(); instead, you will have to parse the string returned by $http.get() to extract the JavaScript code from the HTML markup.


Alternatively, you may use the Github API to retrieve a gist by its ID. That is probably cleaner than parsing it out of an HTML page.