• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

Need some advise. Digital Ocean Modules

Scheduled Pinned Locked Moved Development
19 Posts 2 Posters 10.4k Views 2 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    strawberry 3.141 Project Sponsor Module Developer
    last edited by Sep 8, 2016, 8:10 PM

    can you show what you’ve got so far and what you want to use from the api (e.g. which methods) ?

    Please create a github issue if you need help, so I can keep track

    A 1 Reply Last reply Sep 8, 2016, 8:15 PM Reply Quote 0
    • A Offline
      andrewchumchal @strawberry 3.141
      last edited by Sep 8, 2016, 8:15 PM

      @strawberry-3.141 I would like to pull the IP and Name and the Status. and here is a copy of my MMM-Digital-Ocean.js file https://raw.githubusercontent.com/andyipod1437/MMM-Digital-Ocean/master/MMM-Digital-Ocean.js

      1 Reply Last reply Reply Quote 0
      • S Offline
        strawberry 3.141 Project Sponsor Module Developer
        last edited by Sep 8, 2016, 9:16 PM

        this should give you a litte help
        node_helper.js

        const DIGITALOCEAN = require('dropletapi').Droplets;
        const NodeHelper = require('node_helper');
        
        module.exports = NodeHelper.create({
            
            digitalocean: null,
        
            start: function() {
                console.log("Starting module: " + this.name);
            },
        
            socketNotificationReceived: function(notification, payload) {
                if (notification === "CONFIG") {
                    this.config = payload;
                    this.digitalocean = new DIGITALOCEAN(this.config.api_key);
                    setInterval(() => {
                        this.getData();
                    }, this.config.updateInterval);
                    this.getData();
                }
            },
            
            getData: function() {
                this.digitalocean.listDroplets((error, result) => {
                    if (error) {
                        console.log(error);
                    } else {
                        this.sendSocketNotification("DATA", result);
                    }
                });
            }
        });
        

        MMM-Digital-Ocean.js in start method

        this.sendSocketNotification("CONFIG", this.config);
        

        in socketNotificationReceived

        if(notification === "DATA"){
            this.droplets = payload;
        }
        

        in getDom you can iterate over all droplets and build the output you want

        Please create a github issue if you need help, so I can keep track

        A 1 Reply Last reply Sep 8, 2016, 9:21 PM Reply Quote 0
        • A Offline
          andrewchumchal @strawberry 3.141
          last edited by Sep 8, 2016, 9:21 PM

          @strawberry-3.141

          where do i add the very last part ?

          S 1 Reply Last reply Sep 8, 2016, 9:22 PM Reply Quote 0
          • S Offline
            strawberry 3.141 Project Sponsor Module Developer @andrewchumchal
            last edited by Sep 8, 2016, 9:22 PM

            @andrewchumchal also in MMM-Digital-Ocean.js

            Please create a github issue if you need help, so I can keep track

            A 1 Reply Last reply Sep 8, 2016, 9:24 PM Reply Quote 0
            • A Offline
              andrewchumchal @strawberry 3.141
              last edited by Sep 8, 2016, 9:24 PM

              @strawberry-3.141

              Any where ? or in a function called socketNotificationReceived

              S 1 Reply Last reply Sep 8, 2016, 9:26 PM Reply Quote 0
              • S Offline
                strawberry 3.141 Project Sponsor Module Developer @andrewchumchal
                last edited by Sep 8, 2016, 9:26 PM

                @andrewchumchal

                socketNotificationReceived: function(notification, payload){
                    if(notification === "DATA"){
                       this.droplets = payload;
                    }
                },
                

                Please create a github issue if you need help, so I can keep track

                A 2 Replies Last reply Sep 8, 2016, 9:29 PM Reply Quote 0
                • A Offline
                  andrewchumchal @strawberry 3.141
                  last edited by Sep 8, 2016, 9:29 PM

                  @strawberry-3.141
                  Thanks again for all of you help. Now I just need to get the getDom to work :)

                  1 Reply Last reply Reply Quote 0
                  • A Offline
                    andrewchumchal @strawberry 3.141
                    last edited by Sep 8, 2016, 9:39 PM

                    @strawberry-3.141

                    Any ideas where i can start? like where i can get the name and status.

                    S 1 Reply Last reply Sep 8, 2016, 10:27 PM Reply Quote 0
                    • S Offline
                      strawberry 3.141 Project Sponsor Module Developer @andrewchumchal
                      last edited by Sep 8, 2016, 10:27 PM

                      @andrewchumchal

                      for(var i = 0; i < this.droplets.droplets.length; i++;){
                          var name = this.droplets.droplets[i].name;
                          var status = this.droplets.droplets[i].status;
                          var ip = '';
                          for(var n = 0; n < this.droplets.droplets[i].networks['v4'].length; n++;){
                              ip += this.droplets.droplets[i].networks['v4'].ip_address + ' | ';
                          }
                          for(var n = 0; n < this.droplets.droplets[i].networks['v6'].length; n++;){
                              ip += this.droplets.droplets[i].networks['v6'].ip_address + ' | ';
                          }
                          ip = ip.replace(/ | $/, '');
                      }
                      
                      

                      Please create a github issue if you need help, so I can keep track

                      A 1 Reply Last reply Sep 8, 2016, 10:28 PM Reply Quote 0
                      • 1
                      • 2
                      • 1 / 2
                      1 / 2
                      • First post
                        6/19
                        Last post
                      Enjoying MagicMirror? Please consider a donation!
                      MagicMirror created by Michael Teeuw.
                      Forum managed by Sam, technical setup by Karsten.
                      This forum is using NodeBB as its core | Contributors
                      Contact | Privacy Policy