Original Purpose

Combined Sewer Systems

Original Purpose

Combined Sewer Systems

Green Learning Station

Green Learning Station Pavement Test Area

Green Learning Station

Green Learning Station Pavement Test Area (Top View)

Green Learning Station

Green Learning Station Pavement Test Area (Side View)

Green Learning Station

Green Learning Station Map

Methodology

Site Specifications

Linksys Running OpenWRT

Linksys Router Running OpenWRT

Sensor Relays

Sensor Relay Cabinet

GPS

Sensor GPS Locations

The Basic Action

class Action

  BASE    = Pathname.new(File.join(File.dirname(File.expand_path __FILE__),'..')).realpath
  ENVS    = File.join(BASE,'virtual-env')
  ...

  def initialize(args) ...

  def set_options() ...

  def settings()
    YAML.load_file(File.join(ENVS,@args[0],'environment.yml'))
  end

  def optparse()
    if @opts.nil?
      STDERR.puts "Option Parser for Action is Unimplemented"
      exit 4
     ...

  def validate() ...

  def run() ...

Secure Action Options

class SecureAction < Action

  GPG_ID_FILE = File.join(Dir.home, '.password-store', '.gpg-id')

  def set_options()
    super
    @options = {}
    @opts = OptionParser.new do |opts|

      opts.banner = 'Usage: vsense secure [-s <key_file> ] [-p <gpg key id> [-f]]'

      opts.on('-s', '--ssh KEY', 'SSH identity for vagrant user in all new VMs') do |f|
        @options[:ssh_key_file] = f
      end

      opts.on('-p', '--pgp ID', 'ID of PGP key to use for password encryption') do |id|
        @options[:pgp_id] = id
      end

      opts.on('-f', '--force', "Overwrite existing PGP ID in #{GPG_ID_FILE}") do |f|
        @options[:force_pgp] = f
      end

      opts.on_tail("-h", "--help", "Show this message") do
        STDERR.puts opts
        exit
      end

    end
  end

Run Action Create Options

  def run()
    super

    if File.exists?(@env_dir)
      STDOUT.puts ('Environment already exists: %s' %[@env_dir]).red
      exit 2
    end

    ...
    
    else # default is :run

      puts ('Creating Runtime Environment: %s' % @args[0]).green

      # configuration

      for i in env_config['servers'].keys
        env_config['servers'][i]['hostname'].sub!('%env%',@args[0])
      end

      if not @options[:fixture].nil?
        env_config['fixture'] = @options[:fixture].to_s
      end

      # connected to a build environment?

      if not @options[:build].nil?
        build_config = YAML.load_file(File.join(ENVS,@options[:build],"environment.yml"))
        env_config['repository']['host'] = '%s.%s' % [build_config['servers']['repository']['hostname'], build_config['domain']]
        env_config['repository']['custom'] = true
        env_config['repository']['ip'] = build_config['servers']['repository']['ip']
        env_config['repository']['ip_regex'] = '^' + build_config['servers']['repository']['ip'].gsub('.','\.')
        env_config['repository']['protocol'] = 'http'
      end

      env_config['database']['type'] = @options[:database].to_s
      env_config['servers']['bigsense']['os'] = @options[:os].to_s
      env_config['servers']['ltsense']['os'] = @options[:os].to_s
      env_config['repository']['stage'] = @options[:stage].to_s

    end

Environment

require 'yaml'
require_relative "action"

class Environment

  DEFAULT_VIRTUALBOX_IMGS = {
    'ubuntu' => 'ubuntu/trusty64',
    'debian' => 'puppetlabs/debian-7.8-64-nocm',
    'centos' =>  'chef/centos-7.0',
    'opensuse' => 'webhippie/opensuse-13.1'
  }

  ENV_FILE = File.join(Action::ENVS,'vsense.yml')
  @@settings = File.exists?(ENV_FILE) ? YAML.load_file(ENV_FILE) : { 'environments' => [], 'security' => {}, 'boxes' => DEFAULT_VIRTUALBOX_IMGS }
  @@env_settings = @@settings['environments']
  @@sec_settings = @@settings['security']

  def self.add(name,env_type)
    @@env_settings << { 'name' => name , 'type' => env_type }
    save_env_list
  end

  def self.del(name)
    @@settings['environments'] = @@env_settings.reject { |h| h['name'] == name }
    save_env_list
  end

Environment

class VagrantEnv

  def initialize(global_yml='../vsense.yml', local_yml='environment.yml')
    @vars = YAML.load_file(local_yml)
    @vsense = YAML.load_file(global_yml)
  end

  # security

  def ssh_security_enabled?()
    not @vsense['security']['ssh_key_file'].nil?
  end

  def ssh_identity_key_file()
    @vsense['security']['ssh_key_file']
  end

  # end security

  def ip(server)
    @vars['servers'][server]['ip']
  end

Environment

VAGRANTFILE_API_VERSION = "2"

require './vagrantenv'
vars = VagrantEnv.new

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  config.vm.box = vars.vbox_image('ubuntu')

  if vars.ssh_security_enabled?
    config.ssh.private_key_path = [ File.join(ENV['HOME'], '.vagrant.d', 'insecure_private_key') , vars.ssh_identity_key_file()]
  end

  config.hostmanager.enabled = true
  config.hostmanager.manage_host = true
  config.hostmanager.ignore_private_ip = false
  config.hostmanager.include_offline = true

  config.vm.define "database" do |database|
    database.vm.network :private_network, ip: vars.ip('database')
    database.vm.hostname = vars.hostname('database')
    database.hostmanager.aliases = vars.aliases('database')
    database.vm.provision "ansible" do |ansible|
      ansible.playbook = "ansible/database.yml"
    end
  end
  ...

Sense XML



    
        
            
                34
            
            
                50
            
            
            2.45
        
    

BigSense Web Service API

BigSense API Chart

Example Query

Example Query