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?
Thanks,

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 = 'https://gist.githubusercontent.com/<username>/<gist-id>/raw/filename.js';

$browser.get(scriptUrl)
  .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);
      })
  });
3 Likes

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.

2 Likes

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.

2 Likes