Documentation
¶
Index ¶
- Variables
- func Alphanumeric(name string) string
- func CPUArchToBits(arch string) string
- func ConvertStringsToPairs(input []string) map[string]string
- func ConvertStringsToRegexPairs(input []string) map[string]string
- func ExtractCPUArch(input string) string
- func ExtractFieldsFromDiffMap(diffMap map[string]interface{}, field []string) map[string]interface{}
- func ExtractFunctionName(i interface{}) string
- func ExtractFunctionNameWithTrimPrefix(i interface{}, prefix string) string
- func ExtractJSONTagsFromStruct(inputStruct interface{}) []string
- func ExtractJSONTagsFromStructIntoString(inputStruct interface{}) string
- func FilterInterfaceName(ifaceName string, ifaceFilter string) bool
- func GenerateDeviceTypeSlug(manufacturerName string, modelName string) string
- func GeneratePlatformName(osDistribution string, osMajorVersion string, cpuArch string) string
- func GetIPVersion(ipAddress string) int
- func GetPrefixAndMaskFromIPAddress(ipAddress string) (string, int, error)
- func IsPermittedIPAddress(ipAddress string, permittedSubnets []string, ignoredSubnets []string) bool
- func JSONDiffMapExceptID(newObj, existingObj interface{}, resetFields bool, ...) (map[string]interface{}, error)
- func LoadExtraCert(certPath string) (*x509.CertPool, error)
- func LoadExtraCertInTransportConfig(certPath string) (*http.Transport, 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 NewHTTPClient(validateCert bool, caFile string) (*http.Client, error)
- func RemoveZoneIndexFromIPAddress(ipAddress string) string
- func ReverseLookup(ipAddress string) string
- func SerializeEmails(emails []string) []string
- func SerializeManufacturerName(manufacturer string) string
- func SerializeMask(mask string) string
- func SerializeOSName(os string) string
- func SerializeOwner(owner string) string
- func SerializeOwners(owners []string) []string
- func Slugify(name string) string
- func StructToNetboxJSONMap(obj interface{}) map[string]interface{}
- func SubnetContainsIPAddress(ipAddress string, subnet string) bool
- func ValidateRegexRelations(regexRelations []string) error
- func VerifySubnet(subnet string) bool
- type IDObject
Constants ¶
This section is empty.
Variables ¶
var ManufacturerMap = map[string]string{
".*Cisco.*": "Cisco",
".*Fortinet.*": "Fortinet",
".*Dell.*": "Dell",
"FTS Corp": "Fujitsu",
".*Fujitsu.*": "Fujitsu",
"^HP$": "HPE",
"^HP .*": "HPE",
".*Huawei.*": "Huawei",
".*Inspur.*": "Inspur",
".*Intel.*": "Intel",
"LEN": "Lenovo",
".*Nvidea.*": "Nvidia",
".*Samsung.*": "Samsung",
}
ManufacturerMap maps regex of manufacturer names to manufacturer name. Manufacturer names are compatible with device type library. See internal/devices/combined_data.go for more info.
var SpecificOSMap = map[string]string{
"rhcos_x64": "RHCOS (64bit)",
".*Red Hat Enterprise Linux CoreOS.*": "RHCOS",
".*windows_2022.*": "Microsoft Windows 2022",
".*ol_5x64.*": "Oracle Linux 5 (64-bit)",
".*ol_6x64.*": "Oracle Linux 6 (64-bit)",
".*ol_7x64.*": "Oracle Linux 7 (64-bit)",
".*ol_8x64.*": "Oracle Linux 8 (64-bit)",
".*ol_9x64.*": "Oracle Linux 9 (64-bit)",
"Microsoft Windows Server": "Microsoft Windows Server",
}
SpecificOSMap maps regex of OS names to serialized OS names.
var UniversalOSMap = map[string]string{
".*Red Hat Enterprise Linux.*": "RHEL",
".*Windows.*": "Microsoft Windows",
".*ol_.*": "Oracle Linux",
"^Oracle$": "Oracle Linux",
".*Oracle Linux Server.*": "Oracle Linux",
".*Centos.*": "Centos Linux",
".*Rocky.*": "Rocky Linux",
".*Alma.*": "Alma Linux",
".*Ubuntu.*": "Ubuntu Linux",
}
Universal OSMap maps regex of OS names to serialized OS names.
Functions ¶
func Alphanumeric ¶
Converts string name to its alphanumeric representation with underscored only.
func CPUArchToBits ¶
CPUArchToBits maps cpu architecture to corresponding bits of the architecture: x86_64 -> 64-bit, arm -> 32-bit.... CPUArchToBits maps cpu architecture to corresponding bits of the architecture.
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 ExtractCPUArch ¶
extractCPUArch extracts the CPU architecture from an input string. If no CPU architecture was found, empty string is returned.
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 ExtractFunctionNameWithTrimPrefix ¶
ExtractFunctionNameWithTrimPrefix extracts the function name and trims the prefix. Note: This function sacrifices type safety and assumes the caller ensures the correct usage.
func ExtractJSONTagsFromStruct ¶
func ExtractJSONTagsFromStruct(inputStruct interface{}) []string
func ExtractJSONTagsFromStructIntoString ¶
func ExtractJSONTagsFromStructIntoString(inputStruct interface{}) string
func FilterInterfaceName ¶
Function that returns true if the given interface name should be filtered out, or false if it shouldn't be.
func GenerateDeviceTypeSlug ¶
GenerateDeviceTypeSlug generates a device type slug from the given manufacturer and model.
func GeneratePlatformName ¶
Function that takes osDistribution (Linux, Windows, ...), osMajorVersion (8, 9, 10, ...) and cpuArch (x86_64, or 64bit, ....) and generates universal platform name in the format of "osDistrbution osMajorVersion (cpuArch)".
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 GetPrefixAndMaskFromIPAddress ¶
GetmaskAndPrefixFromIPAddress extracts mask and prefix from a given ipAddress of format ip/mask. 192.168.1.1/24 --> (192.168.1.0/24, 24).
func IsPermittedIPAddress ¶
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 LoadExtraCert ¶
Function that loads additional certs from the given certDirPath. In case empty certPath is provided, deefault cert pool is returned.
func LoadExtraCertInTransportConfig ¶
Function that returns Transport config with extra cert from cert path loaded.
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 ¶
NetboxJSONMarshal 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 NewHTTPClient ¶
NewHTTPClient creates an http client with tls config depending on validateCert and caFile parameter.
func RemoveZoneIndexFromIPAddress ¶
RemoveZoneIndexFromIPAddress removes zone index from the IPv6 address: e.g. 2001:db8::1%eth0 -> 2001:db8::1. e.g. 2001:db8::1%2/64 -> 2001:db8::1/64.
func ReverseLookup ¶
func SerializeEmails ¶
SerializeEmails receieve an array of emails and transforms each array to lowercase strings and removes any whitespace.
func SerializeManufacturerName ¶
GetManufactuerFromString returns manufacturer name from the given string.
func SerializeMask ¶
SerializeMask serializes mask into a bit representation. If a mask is already in bit rerpesentation, it returns the mask: mask "24" -> "24", mask "255.255.255.0" -> "24".
func SerializeOSName ¶
SerializeOSName returns serialized OS name from the given string.
func SerializeOwner ¶
SerializeOwner receives an owner string and serializes it in the following way. If owner string is composed of name and surname, it returns the name and surname capitalized and separated by a space. If owner string is composed of only one word, it returns the word capitalized.
func SerializeOwners ¶
SerializeOwners receives an array of owners and serializes each owner in the following way. If owner string is composed of name and surname, it returns the name and surname capitalized and separated by a space.
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{}
StructToNetboxJSONMap 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 ¶
SubnetContainsIPAddress 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 ValidateRegexRelations ¶
Validates array of regex relations Regex relation is a string of format "regex = value".
func VerifySubnet ¶
VerifySubnet checks if a given subnet is valid.