Documentation ¶
Index ¶
- func Alphanumeric(name string) string
- func ConvertStringsToPairs(input []string) map[string]string
- func ConvertStringsToRegexPairs(input []string) map[string]string
- func ExtractFunctionName(i interface{}) string
- func ExtractPrefixFromIPAddress(ipAddress string) (string, error)
- func FilterInterfaceName(ifaceName string, ifaceFilter string) bool
- func GeneratePlatformName(osType string, osVersion string) string
- func GetIPVersion(ipAddress string) int
- func JSONDiffMapExceptID(newObj, existingObj interface{}, resetFields bool, ...) (map[string]interface{}, error)
- func Lookup(hostname string) string
- func MaskToBits(mask string) (int, error)
- func MatchNamesWithEmails(ctx context.Context, names []string, emails []string, logger *logger.Logger) map[string]string
- func MatchStringToValue(input string, patterns map[string]string) (string, error)
- func NetboxJSONMarshal(obj interface{}) ([]byte, error)
- func ReverseLookup(ipAddress string) string
- func Slugify(name string) string
- func StructToNetboxJSONMap(obj interface{}) map[string]interface{}
- func SubnetContainsIPAddress(ipAddress string, subnet string) bool
- func SubnetsContainIPAddress(ipAddress string, subnets []string) bool
- func ValidateRegexRelations(regexRelations []string) error
- func VerifySubnet(subnet string) bool
- type IDObject
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Alphanumeric ¶
Converts string name to its alphanumeric representation with underscored only.
func ConvertStringsToPairs ¶
Converts strings of format fieldName = value to map[fieldName] = value.
func ConvertStringsToRegexPairs ¶
Converts array of strings, that are of form "regex = value", to a map where key is regex and value is value.
func ExtractFunctionName ¶
func ExtractFunctionName(i interface{}) string
ExtractFunctionName attempts to extract the name of a function regardless of its signature. Note: This function sacrifices type safety and assumes the caller ensures the correct usage.
func ExtractPrefixFromIPAddress ¶ added in v0.4.0
ExtractPrefixFromIPAddress extracts network with mask from the given ipAddress of format ip/mask, e.g. 172.16.2.1/16 -> 172.16.0.0/16.
func FilterInterfaceName ¶ added in v0.3.8
Function that returns true if the given interface name should be filtered out, or false if it shouldn't be.
func GeneratePlatformName ¶
Function that takes osType and osVersion and returns a an universal platform name that then can be shared between multiple objects.
func GetIPVersion ¶
GetIPVersion returns the version of the IP address. It returns 4 for IPv4, 6 for IPv6, and 0 if the IP address is invalid.
func JSONDiffMapExceptID ¶
func JSONDiffMapExceptID(newObj, existingObj interface{}, resetFields bool, source2priority map[string]int) (map[string]interface{}, error)
JSONDiffMapExceptID compares two objects and returns a map of fields (represented by their JSON tag names) that are different with their values from newObj. If resetFields is set to true, the function will also include fields that are empty in newObj but might have a value in existingObj. Also we check for priority, if newObject has priority over existingObject we use the fields from newObject, otherwise we use the fields from exisingObject.
func Lookup ¶
Function that receives hostname and performs a forward lookup to get the IP address. If the forward lookup fails, it returns an empty string.
func MaskToBits ¶
Function that converts string representation of ipv4 mask (e.g. 255.255.255.128) to bit representation (e.g. 25).
func MatchNamesWithEmails ¶
func MatchNamesWithEmails(ctx context.Context, names []string, emails []string, logger *logger.Logger) map[string]string
Function that matches array of names to array of emails (which could be subset of it). It returns a map of name -> email.
E.g. names = ["John Doe", "Jane Doe"], emails = ["jane.doe@example"] Output: map["Jane Doe"] = "jane.doe@example".
func MatchStringToValue ¶
Matches input string to a regex from input map patterns, and returns the value. If there is no match, it returns an empty string.
func NetboxJSONMarshal ¶
This function takes an object pointer, and returns a json body, that can be used to create that object in netbox API. This is essential because default marshal of the object isn't compatible with netbox API when attributes have nested objects.
func ReverseLookup ¶
Function that receives ipAddress and performs a reverse lookup to get the hostname. If the reverse lookup fails, it returns an empty string.
func Slugify ¶
Converts string name to its slugified version. Slugified version can only contain: lowercase letters, numbers, underscores or hyphens. e.g. "My Name" -> "my-name" e.g. " @Test@ " -> "test".
func StructToNetboxJSONMap ¶
func StructToNetboxJSONMap(obj interface{}) map[string]interface{}
Function that converts an object to a map[string]interface{} which can be used to create a json body for netbox API, especially for POST requests.
func SubnetContainsIPAddress ¶
Function that checks if given IP address is part of the given subnet (e.g. ipAddress "172.31.4.129" and subnet "172.31.4.145/25").
func SubnetsContainIPAddress ¶ added in v0.3.7
SubnetsContainIPAddress checks if array of subnets contain, the ip address.
func ValidateRegexRelations ¶
Validates array of regex relations Regex relation is a string of format "regex = value".
func VerifySubnet ¶ added in v0.3.7
VerifySubnet checks if a given subnet is valid.