Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Anyone using UptimeRobot's API?
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Anyone using UptimeRobot's API?

FreekFreek Member
edited June 2012 in Help

I was wondering if anyone's using UptimeRobot's API?
I found this piece of php code which displays all your monitored services in a nice table, but it shows the all time uptime, so not per month:
http://forum.youhosting.com/post8969.html#p8969
I tried changing the 'alltimeuptimeratio' to ''customUptimeRatio=30' as per UptimeRobot's API, but then it doesn't show any uptime stats anymore

Thanked by 1djvdorp

Comments

  • gbshousegbshouse Member, Host Rep
    edited June 2012

    Try this

    Instead of
    if ($monitor['alltimeuptimeratio'] > 95) { echo "<b style=\"color:green;\">" . $monitor['alltimeuptimeratio'] . "%</b></td></tr>"; } else { echo "<b style=\"color:red;\">" . $monitor['alltimeuptimeratio'] . "%</b></td></tr>"; }

    and
    $url = "http://api.uptimerobot.com/getMonitors?apiKey=" . $apiKey . "&format=xml";

    use

    if ($monitor['customuptimeratio'] > 95) { echo "<b style=\"color:green;\">" . $monitor['customuptimeratio'] . "%</b></td></tr>"; } else { echo "<b style=\"color:red;\">" . $monitor['customuptimeratio'] . "%</b></td></tr>"; }

    and
    $url = "http://api.uptimerobot.com/getMonitors?apiKey=" . $apiKey . "&customUptimeRatio=30&format=xml";

  • subigosubigo Member

    @gbshouse said: if ($monitor['customuptimeratio'] > 95) {

    echo "" . $monitor['customuptimeratio'] . "%";
    }
    else {
    echo "" . $monitor['customuptimeratio'] . "%";
    }
    }

    Why on Earth are you using an if/else statement to echo a single variable?

    Thanked by 3djvdorp gbshouse tux
  • aubsaubs Member
    edited June 2012

    I was wondering the same thing.

    If it's over 95, echo it, if not echo it.

    Edit : yeah, makes sense now.

  • gbshousegbshouse Member, Host Rep
    edited June 2012

    I've updated the sample from the first post but it looks that HTML tags were removed

    Updated my previous comment with this f***ing markdown

  • FreekFreek Member

    @gbshouse Thanks, that indeed did solve the problem :)
    I also added the type of check without problems. However, I do have problems adding the log 'datetime' and log 'type'. It doesn't display anything in the last two columns (Last Error says 'Not available', At is empty), but the xml file does contain these values..

    Here's the code I have now: http://pastebin.com/dYtjCJBn
    UptimeRobot's API can be found here: http://uptimerobot.com/api.asp

  • gbshousegbshouse Member, Host Rep
    edited June 2012

    @Freek - as far as I can see from API doc "datetime" and "type" are the attributes of "log" not "monitor" so you should add something like

    foreach($xml->monitor as $monitor) {

    foreach($monitor->log as $log) {
    echo $log['datetime'];
    echo $log['type'];
    }

    }

    Try to read documentation once again including samples :)

    Note - I'm writing straight from my head using my phone and I'm not PHP expert :)

  • nabonabo Member

    @gbshouse said: Updated my previous comment with this f***ing markdown

    What's so difficult with Markdown? It's what we've been using since Usenet all day long.

  • gbshousegbshouse Member, Host Rep

    Nothing - just used to use HTML to format posts on dev forums :)

  • FreekFreek Member
    edited June 2012

    @gbshouse Hmm, looks to me datetime and type are attributes of log.. xml says this:

    http://pastebin.com/MyM0aXTT

  • dnomdnom Member

    @gbshouse use < pre >

     <?php -----
    -------- ?>

    < / pre >

  • MrDOSMrDOS Member
    edited June 2012

    @gbshouse @Freek Or just put four spaces at the beginning of each line.

    See? Like this!
    Multiple lines, too,
      and    arbitrary  spacing
    works just fine. <foo>So</foo> *do* \escapes\.
    
  • gbshousegbshouse Member, Host Rep
    edited June 2012

    @Freek - yes, those props. belongs to log not to monitor but your code uses them in context of monitor not log. Try to use my snippet from one of the previous entries. Beside that yor are using log variable but never assigning the value to it for ex. like the first log entry from monitor object.

  • I know this is a little offtopic, but does anyone know if they offer plans above 50 servers?

  • gbshousegbshouse Member, Host Rep

    Contact them

  • jarjar Patron Provider, Top Host, Veteran

    Thanks for this share. UptimeRobot has been extremely accurate for me. In a year of using it I've not had one false report.

  • gbshousegbshouse Member, Host Rep

    @jarland - I agree, UptimeRobot is better than monitor.us and site24x7 (which I used previously)

  • FreekFreek Member

    @gbshouse Thanks, I managed to got it to work! :)
    Now I need to skin it a little bit, because now it looks like this:
    Image and video hosting by TinyPic
    It does the job, but we all love a little eye candy, don't we :)

    Here's the source. Note that's not fully ready yet. I need to add some more status codes etc. Will post the final source when I'm ready.

    <?php
    echo "<table>NameStatusMonthly UptimeTypeLast ErrorAt";
    $apiKey = "YOUR_API_KEY_HERE";
    $url = "http://api.uptimerobot.com/getMonitors?apiKey=" . $apiKey . "&customUptimeRatio=30&logs=1&format=xml";
    $xml = file_get_contents($url);
    $xml = new SimpleXMLElement ($xml);
    foreach($xml->monitor as $monitor) {
      echo "";
      echo "";
      echo $monitor['friendlyname'];
      echo "";
      if ($monitor['status'] == 2) {
        echo "Online";
      }
      elseif ($monitor['status'] == 8) {
        echo "Offline";
      }
      elseif ($monitor['status'] == 9) {
        echo "Offline";
      }
      else {
        echo "Not Available";
      }
      echo "";
      if ($monitor['alltimeuptimeratio'] > 95) {
        echo "" . $monitor['customuptimeratio'] . "%";
      }
      else {
        echo "" . $monitor['customuptimeratio'] . "%";
      }
    
      echo "";
      if ($monitor['type'] == 3) {
        echo "Ping" . "";
      }
      elseif ($monitor['subtype'] == 2) {
        echo "HTTPS (443)" . "";
      }
    foreach($monitor->log as $log) {
      echo "";
    
    if ($log['type'] == 2) {
        echo "Came Online";
      }
      elseif ($log['type'] == 1) {
        echo "Went Offline";
      }
      else {
        echo "Not Available";
      }
    echo "";
     echo $log['datetime'];
      echo "";
    
    }
    }
    echo "";
    ?>
    
  • @Freek why is that epic if/else statement still there?

    if a
    then b
    else
    then b

    makes no sense :p

  • FreekFreek Member

    @djvdorp Because I just wanted to see the 'log' part working first :P I will remove it in the 'final' version ;)

  • ^.^ I don't get that... It sort of defeats all purpose.

    Oh, look, if this matches, output a var, if it doesnt, output it anyway. -sighface.

    Might start using this, just to keep an eye on certain things I own ;']!

Sign In or Register to comment.