Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhide facts service url flag #172

Merged
merged 4 commits into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,17 @@ The script will ask you for some input.

- `ssh-address`: the address to which the trento-agent should be reachable for ssh connection by the runner for check execution.
- `server-ip`: the address where Trento server can be reached.
- `facts-service-url`: the address of the AMQP service shared with Wanda where fact gathering request are received.
- `api-key`: the API key generated by the server that allows agents to actually communicate with the control plane

You can pass these arguments as flags or env variables too:

```
curl -sfL https://raw.githubusercontent.com/trento-project/agent/main/install-agent.sh | sudo bash -s - --ssh-address=192.168.33.10 --server-url=http://192.168.33.1 --api-key <some-api-key>
curl -sfL https://raw.githubusercontent.com/trento-project/agent/main/install-agent.sh | sudo bash -s - --ssh-address=192.168.33.10 --server-url=http://192.168.33.1 --facts-service-url=amqp://guest:guest@localhost:5672 --api-key <some-api-key>
```

```
SSH_ADDRESS=192.168.33.10 SERVER_IP=192.168.33.1 API_KEY=<some-api-key> sudo ./install-agent.sh
SSH_ADDRESS=192.168.33.10 SERVER_IP=192.168.33.1 FACTS_SERVICE_URL=amqp://guest:guest@localhost:5672 API_KEY=<some-api-key> sudo ./install-agent.sh
```

## Starting Trento Agent service
Expand Down
6 changes: 2 additions & 4 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ func LoadConfig(fileSystem afero.Fs) (*agent.Config, error) {
AgentID: agentID,
InstanceName: hostname,
DiscoveriesConfig: discoveriesConfig,
// Feature flag to enable the facts engine
FactsEngineEnabled: viper.GetBool("factsengine"),
FactsServiceURL: viper.GetString("facts-service-url"),
PluginsFolder: viper.GetString("plugins-folder"),
FactsServiceURL: viper.GetString("facts-service-url"),
PluginsFolder: viper.GetString("plugins-folder"),
}, nil
}
7 changes: 4 additions & 3 deletions cmd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ func (suite *AgentCmdTestSuite) SetupTest() {
AgentID: "some-agent-id",
},
},
FactsEngineEnabled: false,
FactsServiceURL: "amqp://guest:guest@localhost:5672",
PluginsFolder: "/usr/etc/trento/plugins/",
FactsServiceURL: "amqp://guest:guest@serviceurl:5672",
PluginsFolder: "/usr/etc/trento/plugins/",
}
}

Expand All @@ -84,6 +83,7 @@ func (suite *AgentCmdTestSuite) TestConfigFromFlags() {
"--server-url=http://serverurl",
"--api-key=some-api-key",
"--force-agent-id=some-agent-id",
"--facts-service-url=amqp://guest:guest@serviceurl:5672",
})

_ = suite.cmd.Execute()
Expand All @@ -105,6 +105,7 @@ func (suite *AgentCmdTestSuite) TestConfigFromEnv() {
os.Setenv("TRENTO_SERVER_URL", "http://serverurl")
os.Setenv("TRENTO_API_KEY", "some-api-key")
os.Setenv("TRENTO_FORCE_AGENT_ID", "some-agent-id")
os.Setenv("TRENTO_FACTS_SERVICE_URL", "amqp://guest:guest@serviceurl:5672")

_ = suite.cmd.Execute()

Expand Down
11 changes: 0 additions & 11 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,7 @@ func NewStartCmd() *cobra.Command {
panic(err)
}

startCmd.Flags().
Bool("factsengine", false, "Enable the facts engine")
err = startCmd.Flags().MarkHidden("factsengine")
if err != nil {
panic(err)
}

startCmd.Flags().String("facts-service-url", "amqp://guest:guest@localhost:5672", "Facts service queue url")
err = startCmd.Flags().MarkHidden("facts-service-url")
if err != nil {
panic(err)
}

return startCmd
}
Expand Down
29 changes: 20 additions & 9 deletions install-agent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ your single pane of glass on your SAP Applications.

Usage:

sudo ./install-agent.sh --ssh-address <host-ip> --server-url <trento-server-url> --api-key <your-api-key>
sudo ./install-agent.sh --ssh-address <host-ip> --server-url <trento-server-url> --api-key <your-api-key> --facts-service-url <amqp-service-url>

Arguments:
--ssh-address The address to which the trento-agent should be reachable for ssh connection by the runner for check execution.
--server-url The trento server url.
--api-key The API key generated byt the trento server installation.
--rolling Use the rolling version instead of the stable one.
--use-tgz Use the trento tar.gz file from GH releases rather than the RPM.
--interval The polling interval in seconds for the discoveries.
--help Print this help.
--ssh-address The address to which the trento-agent should be reachable for ssh connection by the runner for check execution.
--server-url The trento server url.
--facts-service-url The fact gathering service url.
--api-key The API key generated byt the trento server installation.
--rolling Use the rolling version instead of the stable one.
--use-tgz Use the trento tar.gz file from GH releases rather than the RPM.
--interval The polling interval in seconds for the discoveries.
--help Print this help.
END
}

Expand All @@ -39,6 +40,7 @@ fi
ARGUMENT_LIST=(
"ssh-address:"
"server-url:"
"facts-service-url"
"api-key:"
"rolling"
"use-tgz"
Expand Down Expand Up @@ -69,6 +71,11 @@ while [[ $# -gt 0 ]]; do
shift 2
;;

--facts-service-url)
FACTS_SERVICE_URL=$2
shift 2
;;

--api-key)
API_KEY=$2
shift 2
Expand Down Expand Up @@ -100,6 +107,7 @@ AGENT_CONFIG_FILE="$AGENT_CONFIG_PATH/agent.yaml"
AGENT_CONFIG_TEMPLATE='
ssh-address: @SSH_ADDRESS@
server-url: @SERVER_URL@
facts-service-url: @FACTS_SERVICE_URL@
api-key: @API_KEY@
cloud-discovery-period: @INTERVAL@s
cluster-discovery-period: @INTERVAL@s
Expand Down Expand Up @@ -133,7 +141,9 @@ function configure_installation() {
if [[ -z "$SERVER_URL" ]]; then
read -rp "Please provide the server url: " SERVER_URL </dev/tty
fi

if [[ -z "$FACTS_SERVICE_URL" ]]; then
read -rp "Please provide the facts service url: " FACTS_SERVICE_URL </dev/tty
fi
if [[ -z "$API_KEY" ]]; then
read -rp "Please provide the API key: " API_KEY </dev/tty
fi
Expand Down Expand Up @@ -213,6 +223,7 @@ function setup_trento() {
echo "$AGENT_CONFIG_TEMPLATE" |
sed "s|@SERVER_URL@|${SERVER_URL}|g" |
sed "s|@SSH_ADDRESS@|${SSH_ADDRESS}|g" |
sed "s|@FACTS_SERVICE_URL@|${FACTS_SERVICE_URL}|g" |
sed "s|@API_KEY@|${API_KEY}|g" |
sed "s|@INTERVAL@|${interval}|g" \
>${AGENT_CONFIG_FILE}
Expand Down
64 changes: 30 additions & 34 deletions internal/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ type Agent struct {
}

type Config struct {
AgentID string
InstanceName string
DiscoveriesConfig *discovery.DiscoveriesConfig
FactsEngineEnabled bool
FactsServiceURL string
PluginsFolder string
AgentID string
InstanceName string
DiscoveriesConfig *discovery.DiscoveriesConfig
FactsServiceURL string
PluginsFolder string
}

// NewAgent returns a new instance of Agent with the given configuration
Expand Down Expand Up @@ -91,42 +90,39 @@ func (a *Agent) Start(ctx context.Context) error {
return nil
})

if a.config.FactsEngineEnabled {
gathererRegistry := gatherers.NewRegistry(gatherers.StandardGatherers())

gathererRegistry := gatherers.NewRegistry(gatherers.StandardGatherers())
log.Info("loading plugins")

log.Info("loading plugins")

pluginLoaders := gatherers.PluginLoaders{
"rpc": &gatherers.RPCPluginLoader{},
}
pluginLoaders := gatherers.PluginLoaders{
"rpc": &gatherers.RPCPluginLoader{},
}

gatherersFromPlugins, err := gatherers.GetGatherersFromPlugins(
pluginLoaders,
a.config.PluginsFolder,
)
if err != nil {
log.Fatalf("Error loading gatherers from plugins: %s", err)
}
gatherersFromPlugins, err := gatherers.GetGatherersFromPlugins(
pluginLoaders,
a.config.PluginsFolder,
)
if err != nil {
log.Fatalf("Error loading gatherers from plugins: %s", err)
}

gathererRegistry.AddGatherers(gatherersFromPlugins)
gathererRegistry.AddGatherers(gatherersFromPlugins)

c := factsengine.NewFactsEngine(a.config.AgentID, a.config.FactsServiceURL, *gathererRegistry)
c := factsengine.NewFactsEngine(a.config.AgentID, a.config.FactsServiceURL, *gathererRegistry)

g.Go(func() error {
log.Info("Starting fact gathering service...")
if err := c.Subscribe(); err != nil {
return err
}
g.Go(func() error {
log.Info("Starting fact gathering service...")
if err := c.Subscribe(); err != nil {
return err
}

if err := c.Listen(groupCtx); err != nil {
return err
}
if err := c.Listen(groupCtx); err != nil {
return err
}

log.Info("fact gathering stopped.")
return nil
})
}
log.Info("fact gathering stopped.")
return nil
})

return g.Wait()
}
Expand Down
8 changes: 8 additions & 0 deletions packaging/config/agent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,16 @@

# server-url: http://localhost

###############################################################################

## Configure the api-key for trento agent to use in the communication with Trento control plane
## Required.
## Find the api key at <your-trento-installation-url>/settings

# api-key: <the-api-key-generated-by-trento>

###############################################################################

## Facts gathering service URL

# facts-service-url: amqp://guest:guest@localhost:5672
1 change: 1 addition & 0 deletions test/fixtures/config/agent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ subscription-discovery-period: 900s
server-url: http://serverurl
api-key: some-api-key
force-agent-id: some-agent-id
facts-service-url: amqp://guest:guest@serviceurl:5672