Skip to content
Snippets Groups Projects
Select Git revision
2 results Searching

main.go

Blame
  • main.go 9.14 KiB
    package main
    
    import (
    	"flag"
    	"net/http"
    	"github.com/prometheus/client_golang/prometheus/promhttp"
    	"fmt"
    	"os"
    	"github.com/prometheus/common/log"
    	"github.com/prometheus/common/version"
    	"github.com/prometheus/client_golang/prometheus"
    	"sync"
    	"crypto/tls"
    	"io/ioutil"
    	"encoding/json"
    	"bytes"
    	"strconv"
    	"strings"
    )
    
    const (
    	namespace = "nexenta" // For Prometheus metrics.
    	apiPath   = "/rest/nms"
    )
    
    var (
    	listenAddr      = flag.String("listen-address", ":9457", "The address to listen on for HTTP requests.")
    	metricsEndpoint = flag.String("metrics-endpoint", "/metrics", "Path under which to expose metrics.")
    	apiHost         = flag.String("host", "nexenta", "Nexenta API host.")
    	apiPort         = flag.String("port", "8457", "Nexenta API port.")
    	apiUser         = flag.String("user", "admin", "Nexenta API username.")
    	apiPass         = flag.String("password", "password", "Nexenta API password.")
    	apiSsl          = flag.Bool("ssl", false, "Use SSL for the Nexenta API.")
    	insecure        = flag.Bool("insecure", false, "Ignore server certificate if using https.")
    	showVersion     = flag.Bool("version", false, "Print version information.")
    )
    
    type ApiRequest struct {
    	Object  string   `json:"object"`
    	Method  string   `json:"method"`
    	Params  []string `json:"params"`
    }
    
    type ApiResponse struct {
    	TGFlash string      `json:"tg_flash"`
    	Result  interface{} `json:"result"`
    	Error   ApiError    `json:"error"`
    }
    
    type ApiError struct {
    	Message string `json:"message"`
    }
    
    type ResultObject struct {
    	State  []string `json:"state"`
    	Errors []string `json:"errors"`
    }
    
    type ResultSensor struct {
    	Name  string `json:"name"`
    	Value string `json:"value"`
    	State string `json:"state"`
    	Dev   string `json:"dev"`
    	Units string `json:"units"`
    	Type  string `json:"type"`
    }
    
    type Exporter struct {
    	URI    string
    	mutex  sync.Mutex