Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
peekjef72 committed Sep 24, 2023
0 parents commit 557fb52
Show file tree
Hide file tree
Showing 39 changed files with 22,478 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/.project
/.settings
/my_tests
/*.tar.gz
.vscode/
config/
bin/
./httpapi_exporter
./passwd_crypt
httpapi_exporter
passwd_encrypt
23 changes: 23 additions & 0 deletions .promu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
go:
cgo: false
repository:
path: github.com/peekjef72/httpapi_exporter
build:
binaries:
- name: httpapi_exporter
# path: httpapi_exporter
- name: passwd_encrypt
path: ./cmd/passwd_crypt
flags: -a -tags netgo,static
ldflags: |
-X github.com/prometheus/common/version.Version={{.Version}}
-X github.com/prometheus/common/version.Revision={{.Revision}}
-X github.com/prometheus/common/version.Branch={{.Branch}}
-X github.com/prometheus/common/version.BuildDate={{date "20060102-15:04:05"}}
-X github.com/prometheus/common/version.BuildUser={{user}}@{{host}}
tarball:
prefix: .
files:
- LICENSE
- README.md
- contribs/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Alin Sinpalean

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
61 changes: 61 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright 2015 The Prometheus Authors
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

GO := go
GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH)))
PROMU := $(GOPATH)/bin/promu
pkgs = $(shell $(GO) list ./... | grep -v /vendor/)

PREFIX ?= $(shell pwd)
BIN_DIR ?= $(shell pwd)
DOCKER_IMAGE_NAME ?= httpapi_exporter
DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))


all: promu build test

style:
@echo ">> checking code style"
@! gofmt -d $(shell find . -path ./vendor -prune -o -name '*.go' -print) | grep '^'

test:
@echo ">> running tests"
@$(GO) test -short -race $(pkgs)

format:
@echo ">> formatting code"
@$(GO) fmt $(pkgs)

vet:
@echo ">> vetting code"
@$(GO) vet $(pkgs)

build: promu
@echo ">> building binaries"
@$(PROMU) build --prefix $(PREFIX)

tarball: promu
@echo ">> building release tarball"
@$(PROMU) tarball --prefix $(PREFIX) $(BIN_DIR)

docker:
@echo ">> building docker image"
@docker build -t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" .

promu:
@GOOS=$(shell uname -s | tr A-Z a-z) \
GOARCH=$(subst x86_64,amd64,$(patsubst i%86,386,$(shell uname -m))) \
$(GO) install github.com/prometheus/promu@latest


.PHONY: all style format build test vet tarball docker promu
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Prometheus HTTPAPI Exporter

This exporter wants to be a generic JSON REST API exporter. That's mean it can login, then makes requests to collect metrics and performs transformations on values and finally returns metrics in prometheus format.

Nothing is hard coded in the exporter. That why it is a generic exporter.

As examples 3 configurations for exporters are provided (see contribs):
- hp3par_exporter
- veeam_exporter
- netscaler_exporter

1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.3.0
169 changes: 169 additions & 0 deletions actions_action.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
package main

import (
//"bytes"
"fmt"

"github.com/go-kit/log"
"github.com/go-kit/log/level"
)

// ***************************************************************************************
// ***************************************************************************************
// actions (block / loop )
// ***************************************************************************************
// ***************************************************************************************

type ActionsAction struct {
Name *Field `yaml:"name,omitempty"`
With []any `yaml:"with,omitempty"`
When []*exporterTemplate `yaml:"when,omitempty"`
LoopVar string `yaml:"loop_var,omitempty"`
Vars map[string]any `yaml:"vars,omitempty"`
Until []*exporterTemplate `yaml:"until,omitempty"`

Actions []Action `yaml:"actions"`

// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline" json:"-"`
}

func (a *ActionsAction) Type() int {
return actions_action
}

func (a *ActionsAction) GetName(symtab map[string]any, logger log.Logger) string {
str, err := a.Name.GetValueString(symtab, nil, false)
if err != nil {
level.Warn(logger).Log("msg", fmt.Sprintf("invalid action name: %v", err))
return ""
}
return str
}

func (a *ActionsAction) GetNameField() *Field {
return a.Name
}
func (a *ActionsAction) SetNameField(name *Field) {
a.Name = name
}

func (a *ActionsAction) GetWidh() []any {
return a.With
}
func (a *ActionsAction) SetWidth(with []any) {
a.With = with
}

func (a *ActionsAction) GetWhen() []*exporterTemplate {
return a.When

}
func (a *ActionsAction) SetWhen(when []*exporterTemplate) {
a.When = when
}

func (a *ActionsAction) GetLoopVar() string {
return a.LoopVar
}
func (a *ActionsAction) SetLoopVar(loopvar string) {
a.LoopVar = loopvar
}

func (a *ActionsAction) GetVars() map[string]any {
return a.Vars
}
func (a *ActionsAction) SetVars(vars map[string]any) {
a.Vars = vars
}

func (a *ActionsAction) GetUntil() []*exporterTemplate {
return a.Until
}
func (a *ActionsAction) SetUntil(until []*exporterTemplate) {
a.Until = until
}

// func (a *ActionsAction) GetBaseAction() *BaseAction {
// return nil
// }

func (a *ActionsAction) setBasicElement(
nameField *Field,
vars map[string]any,
with []any,
loopVar string,
when []*exporterTemplate,
until []*exporterTemplate) error {
return setBasicElement(a, nameField, vars, with, loopVar, when, until)
}

func (a *ActionsAction) PlayAction(script *YAMLScript, symtab map[string]any, logger log.Logger) error {
return PlayBaseAction(script, symtab, logger, a, a.CustomAction)
}

// WARNING: only the first MetricPrefix in actionsTree if supported
func (a *ActionsAction) GetMetrics() []*GetMetricsRes {
var (
final_res []*GetMetricsRes
)
for _, cur_act := range a.Actions {
res := cur_act.GetMetrics()
if len(res) > 0 {
final_res = append(final_res, res...)
}
}
return final_res
}

// only for MetricAction
func (a *ActionsAction) GetMetric() *MetricConfig {
return nil
}
func (a *ActionsAction) SetMetricFamily(*MetricFamily) {
}

// only for PlayAction
func (a *ActionsAction) SetPlayAction(script map[string]*YAMLScript) error {
for _, a := range a.Actions {
if a.Type() == play_script_action || a.Type() == actions_action {
if err := a.SetPlayAction(script); err != nil {
return err
}
}
}
return nil
}

// specific behavior for the ActionsAction
func (a *ActionsAction) CustomAction(script *YAMLScript, symtab map[string]any, logger log.Logger) error {
level.Debug(logger).Log(
"script", ScriptName(symtab, logger),
"msg", fmt.Sprintf("[Type: ActionsAction] Name: %s - %d Actions to play", a.GetName(symtab, logger), len(a.Actions)))
for _, cur_act := range a.Actions {
// fmt.Printf("\tadd to symbols table: %s = %v\n", key, val)
if err := PlayBaseAction(script, symtab, logger, cur_act, cur_act.CustomAction); err != nil {
return err
}

}
return nil
}

func (a *ActionsAction) AddCustomTemplate(customTemplate *exporterTemplate) error {

if err := AddCustomTemplate(a, customTemplate); err != nil {
return err
}

for _, cur_act := range a.Actions {
err := cur_act.AddCustomTemplate(customTemplate)
if err != nil {
return err
}
}

return nil
}

// ***************************************************************************************
Loading

0 comments on commit 557fb52

Please sign in to comment.