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

Add log collector utility #1847

Merged
merged 23 commits into from
May 29, 2020
Merged
Show file tree
Hide file tree
Changes from 22 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
4 changes: 2 additions & 2 deletions azurelinuxagent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ def __init__(self, verbose, conf_file_path=None):
verbose = verbose or conf.get_logs_verbose()
level = logger.LogLevel.VERBOSE if verbose else logger.LogLevel.INFO
logger.add_logger_appender(logger.AppenderType.FILE, level,
path="/var/log/waagent.log")
path=conf.get_agent_log_file())
if conf.get_logs_console():
logger.add_logger_appender(logger.AppenderType.CONSOLE, level,
path="/dev/console")
path="/dev/console")

if event.send_logs_to_telemetry():
logger.add_logger_appender(logger.AppenderType.TELEMETRY,
Expand Down
5 changes: 5 additions & 0 deletions azurelinuxagent/common/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def load_conf_from_file(conf_file_path, conf=__conf__):

__STRING_OPTIONS__ = {
"Lib.Dir": "/var/lib/waagent",
"Agent.Log": "/var/log/waagent.log",
"DVD.MountPoint": "/mnt/cdrom/secure",
"Pid.File": "/var/run/waagent.pid",
"Extension.LogDir": "/var/log/azure",
Expand Down Expand Up @@ -243,6 +244,10 @@ def get_ext_log_dir(conf=__conf__):
return conf.get("Extension.LogDir", "/var/log/azure")


def get_agent_log_file(conf=__conf__):
return conf.get("Agent.Log", "/var/log/waagent.log")


def get_fips_enabled(conf=__conf__):
return conf.get_switch("OS.EnableFIPS", False)

Expand Down
364 changes: 364 additions & 0 deletions azurelinuxagent/common/logcollector.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion azurelinuxagent/pa/deprovision/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def del_dirs(self, warnings, actions):
actions.append(DeprovisionAction(fileutil.rm_dirs, dirs))

def del_files(self, warnings, actions):
files = ['/root/.bash_history', '/var/log/waagent.log']
files = ['/root/.bash_history', conf.get_agent_log_file()]
actions.append(DeprovisionAction(fileutil.rm_files, files))

# For OpenBSD
Expand Down
73 changes: 73 additions & 0 deletions config/logcollector_manifest_full
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
echo,### Probing Directories ###
pgombar marked this conversation as resolved.
Show resolved Hide resolved
ll,/var/log
ll,$LIB_DIR
ll,/etc/udev/rules.d

echo,### Gathering Configuration Files ###
copy,$LIB_DIR/provisioned
copy,/etc/fstab
copy,/etc/ssh/sshd_config
copy,/boot/grub*/grub.c*
copy,/boot/grub*/menu.lst
copy,/etc/*-release
copy,/etc/HOSTNAME
copy,/etc/hostname
copy,/etc/network/interfaces
copy,/etc/network/interfaces.d/*.cfg
copy,/etc/netplan/50-cloud-init.yaml
copy,/etc/nsswitch.conf
copy,/etc/resolv.conf
copy,/run/systemd/resolve/stub-resolv.conf
copy,/run/resolvconf/resolv.conf
copy,/etc/sysconfig/iptables
copy,/etc/sysconfig/network
copy,/etc/sysconfig/network/ifcfg-eth*
copy,/etc/sysconfig/network/routes
copy,/etc/sysconfig/network-scripts/ifcfg-eth*
copy,/etc/sysconfig/network-scripts/route-eth*
copy,/etc/sysconfig/SuSEfirewall2
copy,/etc/ufw/ufw.conf
copy,/etc/waagent.conf
copy,/var/lib/dhcp/dhclient.eth0.leases
copy,/var/lib/dhclient/dhclient-eth0.leases
copy,/var/lib/wicked/lease-eth0-dhcp-ipv4.xml
echo,

echo,### Gathering Log Files ###
copy,$AGENT_LOG*
copy,/var/log/syslog*
copy,/var/log/rsyslog*
copy,/var/log/messages*
copy,/var/log/kern*
copy,/var/log/dmesg*
copy,/var/log/dpkg*
copy,/var/log/yum*
copy,/var/log/cloud-init*
copy,/var/log/boot*
copy,/var/log/auth*
copy,/var/log/secure*
copy,$LOG_DIR/*/*
copy,$LOG_DIR/*/*/*
copy,$LOG_DIR/custom-script/handler.log
copy,$LOG_DIR/run-command/handler.log
echo,

echo,### Gathering Extension Files ###
copy,$LIB_DIR/ExtensionsConfig.*.xml
copy,$LIB_DIR/*/status/*.status
copy,$LIB_DIR/*/config/*.settings
copy,$LIB_DIR/*/config/HandlerState
copy,$LIB_DIR/*/config/HandlerStatus
copy,$LIB_DIR/GoalState.*.xml
copy,$LIB_DIR/HostingEnvironmentConfig.xml
copy,$LIB_DIR/*.manifest.xml
copy,$LIB_DIR/SharedConfig.xml
copy,$LIB_DIR/ManagedIdentity-*.json
copy,$LIB_DIR/error.json
copy,$LIB_DIR/Incarnation
copy,$LIB_DIR/waagent_status.json
copy,$LIB_DIR/history/*.zip
echo,

echo,### Gathering Disk Info ###
diskinfo,
33 changes: 33 additions & 0 deletions config/logcollector_manifest_normal
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
echo,### Probing Directories ###
pgombar marked this conversation as resolved.
Show resolved Hide resolved
ll,/var/log
ll,$LIB_DIR

echo,### Gathering Configuration Files ###
copy,/etc/*-release
copy,/etc/HOSTNAME
copy,/etc/hostname
copy,/etc/waagent.conf
echo,

echo,### Gathering Log Files ###
copy,$AGENT_LOG*
copy,/var/log/dmesg*
copy,/var/log/syslog*
copy,/var/log/auth*
copy,$LOG_DIR/*/*
copy,$LOG_DIR/*/*/*
copy,$LOG_DIR/custom-script/handler.log
echo,

echo,### Gathering Extension Files ###
copy,$LIB_DIR/*.xml
copy,$LIB_DIR/waagent_status.json
copy,$LIB_DIR/*/status/*.status
copy,$LIB_DIR/*/config/*.settings
copy,$LIB_DIR/*/config/HandlerState
copy,$LIB_DIR/*/config/HandlerStatus
copy,$LIB_DIR/*.agentsManifest
copy,$LIB_DIR/error.json
copy,$LIB_DIR/Incarnation
copy,$LIB_DIR/history/*.zip
echo,
3 changes: 3 additions & 0 deletions config/waagent.conf
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ OS.SshDir=/etc/ssh
#
# Lib.Dir=/var/lib/waagent

# Agent log file. If changed, make sure to update /etc/logrotate.d/waagent.logrotate to continue rolling over agent logs.
# Agent.Log=/var/log/waagent.log

#
# DVD.MountPoint=/mnt/cdrom/secure

Expand Down
1 change: 1 addition & 0 deletions tests/common/test_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class TestConf(AgentTestCase):
"HttpProxy.Port": None,
"DetectScvmmEnv": False,
"Lib.Dir": "/var/lib/waagent",
"Agent.Log": "/var/log/waagent.log",
"DVD.MountPoint": "/mnt/cdrom/secure",
"Pid.File": "/var/run/waagent.pid",
"Extension.LogDir": "/var/log/azure",
Expand Down
Loading