Documentation
¶
Overview ¶
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. More about the os-release: https://www.linux.org/docs/man5/os-release.html
Index ¶
- Variables
- func DateConversion(data string) (string, error)
- func GetHostname() (string, error)
- func GetMachineId() (string, error)
- func NeedsRestarting() (bool, string)
- func PackageBinary() string
- func ParseOSRelease() error
- func SetAuthentication(request *resty.Request)
- func SplitPackageName(package_name string) (name, version, release, epoch, arch string)
- type OSRelease
Constants ¶
This section is empty.
Variables ¶
var Path = "/etc/os-release"
Path contains the default path to the os-release file
Functions ¶
func DateConversion ¶
DateConversion takes a date string input and converts it to RFC3339 format. It attempts to parse the input date string using multiple common date formats and returns the formatted date as a string.
Parameters:
- data: A string representing a date in any common format
Returns:
- string: The date formatted in RFC3339 format (2006-01-02T15:04:05Z07:00)
- error: An error if the date parsing fails, nil otherwise
func GetHostname ¶
GetHostname returns the system hostname by executing the hostname command. It uses the /usr/bin/hostname command to obtain the hostname and returns it as a string. Returns an error if the hostname command execution fails.
func GetMachineId ¶
GetMachineId retrieves the unique machine identifier from the '/etc/machine-id' file. This identifier is typically used to distinguish the host machine in a network.
Returns:
- string: The machine ID as a trimmed string
- error: An error if reading the machine-id file fails
func NeedsRestarting ¶ added in v1.5.0
NeedsRestarting checks if the system needs to be restarted by executing the '/usr/bin/needs-restarting' command. This command is typically available on Red Hat-based systems to determine if any running processes are using files that have been updated/deleted.
Returns:
- bool: true if system needs restarting, false otherwise
- string: the complete output message from needs-restarting command
The function parses the command output looking for the specific phrase "Reboot should not be necessary". If this phrase is found, it indicates no restart is needed.
func PackageBinary ¶
func PackageBinary() string
PackageBinary determines and verifies the appropriate package manager binary (yum or dnf) based on the Linux distribution version. It reads /etc/os-release to check if the system is running RHEL/CentOS 8 or 9, in which case it selects 'dnf' instead of the default 'yum'.
The function also verifies if the selected package manager is installed in the system. If the binary is not found, it exits with an error message.
Returns:
- string: The name of the package manager binary ("yum" or "dnf")
The function will exit with status code 1 if the required package manager is not installed.
func ParseOSRelease ¶ added in v1.2.0
func ParseOSRelease() error
ParseOSRelease parses the os-release file pointing to by Path. The fields are saved into the Release global variable.
func SetAuthentication ¶ added in v1.7.0
SetAuthentication configures authentication for an API request. It prioritizes API key authentication over basic authentication. If an API key is configured in the server.api_key setting, it sets the X-API-Key header. Otherwise, if username and password are configured, it uses basic authentication.
Parameters:
- request: A resty.Request instance to configure with authentication headers
func SplitPackageName ¶
SplitPackageName splits a RPM package name into its components. It takes a package name string as input and returns the following components:
- name: The name of the package
- version: The version number
- release: The release number
- epoch: The epoch number (empty string if not present)
- arch: The architecture
The function expects package names in the following format: [name]-[version]-[release].[arch].rpm or [name]-[epoch]:[version]-[release].[arch].rpm
The .rpm suffix is optional and will be trimmed if present. If epoch is not present in the package name, an empty string is returned for that component.
Types ¶
type OSRelease ¶ added in v1.2.0
type OSRelease struct {
Name string
Version string
ID string
IDLike string
PrettyName string
VersionID string
HomeURL string
DocumentationURL string
SupportURL string
BugReportURL string
PrivacyPolicyURL string
VersionCodename string
UbuntuCodename string
ANSIColor string
CPEName string
BuildID string
Variant string
VariantID string
Logo string
}
var Release OSRelease