tasks

package module
v1.0.0-beta.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 10, 2021 License: MIT Imports: 19 Imported by: 1

README

tasks

The tasks for GoDash dashboard.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Project is set at compile time, used for User-Agent in HTTP requests
	Project = "GoDash"
	// Version is set at compile time, used for User-Agent in HTTP requests
	Version = "0.0.0-beta.0"
	// TaskMapping is used to map different versions of a task to a table section
	// within the GoDash UI
	TaskMapping = map[string][]string{}
	// TaskRunners defines the different types of tasks for the task runner
	TaskRunners = map[string]Type{
		"port":          {Port, "port", false},
		"fakeport":      {FakePort, "port", false},
		"ping":          {Ping, "ping", false},
		"http":          {HTTP, "http", false},
		"http-json":     {HTTPJSON, "http", false},
		"http-status":   {HTTPStatus, "http", false},
		"http-regex":    {HTTPREGEXP, "http", false},
		"http-regexp":   {HTTPREGEXP, "http", false},
		"fakeping":      {FakePing, "ping", false},
		"media":         {Media, "media", false},
		"iframe":        {Media, "media", false},
		"feed":          {Feed, "feed", false},
		"fakefeed":      {FakeFeed, "feed", false},
		"dns":           {DNS, "dns", false},
		"dns-cidr":      {DNSCIDR, "dns", false},
		"counter":       {Counter, "counter", true},
		"redis-counter": {RedisCounter, "counter", true},
	}
)

Functions

func CreateRequest

func CreateRequest(method string, url string, body io.Reader) (*http.Request, *http.Client)

CreateRequest generates HTTP requests for tasks

func Templater

func Templater(str string, data interface{}) string

Templater lets tasks format strings using dynamic structs

func Timerless

func Timerless(task string) bool

Timerless checks if a task should use a timer to update or not

Types

type CleanTask

type CleanTask struct {
	Label     string                 `json:"label"`
	Interval  string                 `json:"interval"`
	Task      string                 `json:"task"`
	ID        string                 `json:"id"`
	Date      int64                  `json:"date"`
	Location  string                 `json:"location,omitempty"`
	Once      bool                   `json:"once,omitempty"`
	Spark     *Spark                 `json:"spark,omitempty"`
	Warn      bool                   `json:"warn,omitempty"`
	Last      interface{}            `json:"last,omitempty"`
	Cancelled bool                   `json:"cancelled,omitempty"`
	Params    map[string]interface{} `json:"-"`
	CTX       context.Context        `json:"-"`
	Cancel    func() bool            `json:"-"`
}

CleanTask is for JSON marshaling, removing hidden params

type Hash

type Hash struct {
	Label    string `json:"label"`
	Interval string `json:"interval"`
	Task     string `json:"task"`
	ID       string `json:"id,omitempty"`
	Once     bool   `json:"once,omitempty"`
	Machine  string `json:"machine,omitempty"`
}

Hash is used to create task hashes for task IDs

type Redis

type Redis struct {
	Enabled bool
	Client  *redis.Client
	Context context.Context
}

Redis holds the Redis client and context

type Result

type Result struct {
	Task         string      `json:"task"`
	Label        string      `json:"label"`
	ID           string      `json:"id"`
	Date         int64       `json:"date"`
	Notification string      `json:"notification,omitempty"`
	Location     string      `json:"location,omitempty"`
	Spark        *Spark      `json:"spark,omitempty"`
	Warn         bool        `json:"warn,omitempty"`
	Update       interface{} `json:"update,omitempty"`
	Error        error       `json:"error"`
	ErrorString  string      `json:"errormsg,omitempty"`
	Event        string      `json:"event,omitempty"`
	Cancelled    bool        `json:"-"`
}

Result is the results from a task execution

func Counter

func Counter(args *TaskArgs) Result

Counter implements Atomic counters for HTTP hooks

func DNS

func DNS(args *TaskArgs) Result

DNS checks if a domain resolves to anything

func DNSCIDR

func DNSCIDR(args *TaskArgs) Result

DNSCIDR validates a dns address with CIDR ranges

func FakeFeed

func FakeFeed(args *TaskArgs) Result

FakeFeed generates fake data for demo dashboards

func FakePing

func FakePing(args *TaskArgs) Result

FakePing generates fake data for demo dashboards

func FakePort

func FakePort(args *TaskArgs) Result

FakePort generates a fake port result for demo dashboards

func Feed

func Feed(args *TaskArgs) Result

Feed pulls different types of RSS feeds

func HTTP

func HTTP(args *TaskArgs) Result

HTTP pulls content from a web server

func HTTPJSON

func HTTPJSON(args *TaskArgs) Result

HTTPJSON lets you parse JSON on a remote web host

func HTTPREGEXP

func HTTPREGEXP(args *TaskArgs) Result

HTTPREGEXP lets you parse HTML with REGEXP

func HTTPStatus

func HTTPStatus(args *TaskArgs) Result

HTTPStatus gets the status code from a web server

func Media

func Media(args *TaskArgs) Result

Media lets you embed iframes, images, videos etc. on in a dashboard

func NewResult

func NewResult(task Task) Result

NewResult generates a new result object for tasks to return

func Ping

func Ping(args *TaskArgs) Result

Ping sends ICMP requests to a specific target host

func Port

func Port(args *TaskArgs) Result

Port checks if a port is open on a target host

func RedisCounter

func RedisCounter(args *TaskArgs) Result

RedisCounter uses Radis for tracking counts

type Spark

type Spark struct {
	Value interface{} `json:"value,omitempty"`
	Warn  bool        `json:"warn,omitempty"`
}

Spark is a sparkline number and warn flag for the UI

type Task

type Task struct {
	Label     string                 `json:"label"`
	Interval  string                 `json:"interval"`
	Task      string                 `json:"task"`
	ID        string                 `json:"id"`
	Date      int64                  `json:"date"`
	Location  string                 `json:"location,omitempty"`
	Once      bool                   `json:"once,omitempty"`
	Spark     *Spark                 `json:"spark"`
	Warn      bool                   `json:"warn,omitempty"`
	Last      interface{}            `json:"last,omitempty"`
	Cancelled bool                   `json:"cancelled,omitempty"`
	Params    map[string]interface{} `json:"params,omitempty"`
	CTX       context.Context        `json:"-"`
	Cancel    func() bool            `json:"-"`
}

Task defines each job passed to the task runner

type TaskArgs

type TaskArgs struct {
	Task     Task         `json:"task"`
	Callback func(Result) `json:"-"`
	Stop     func()       `json:"-"`
	Redis    Redis        `json:"-"`
}

TaskArgs is possible arguments passed to a task

type Type

type Type struct {
	Func      func(*TaskArgs) Result
	Type      string `json:"type"`
	Timerless bool   `json:"timerless"` // Triggered by callbacks
}

Type binds a method to a UI type

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL