#!/bin/bash
# <%= @description %>
# Script generated by Puppet. It's executed when you run:
# puppi info <%= @name %> 
#
# Sources common header for Puppi scripts
. <%= scope.lookupvar('puppi::params::scriptsdir') %>/header || exit 10

<% if @packagename != "" -%>
# Show packages info
echo_title "$HOSTNAME - <%= @name %>: Packages Installed: <% @packagename.each do |item| %><%= item %><% end %>"
<% @packagename.each do |item| -%>
show_command "<%= scope.lookupvar('puppi::params::info_package_query') %> <%= item %>"
<% if @verbose == "yes" -%>
show_command "<%= scope.lookupvar('puppi::params::info_package_list') %> <%= item %>"
<% else -%>
show_command "<%= scope.lookupvar('puppi::params::info_package_list') %> <%= item %> | egrep '(/bin|^/etc|/sbin|log$)'"
<% end -%>
<% end -%>
<% end -%>

<% if @configfile != "" -%>
# Show config info
echo_title "$HOSTNAME - <%= @name %>: Configuration Files managed: <% @configfile.each do |item| %><%= item %><% end %>"
<% @configfile.each do |item| -%>
<% if @verbose == "yes" -%>
show_command "cat <%= item %>"
<% else -%> 
show_command "head <%= item %>"
<% end -%>
<% end -%>
<% end -%>

<% if @datadir != "" -%>
# Show data dir
echo_title "$HOSTNAME - <%= @name %>: Application data are in: <% @datadir.each do |item| %><%= item %><% end %>"
<% @datadir.each do |item| -%>
show_command "ls -latr <%= item %>"
show_command "df <%= item %>"
<% end -%>
<% end -%>

<% if @logdir != "" -%>
# Show log dir
echo_title "$HOSTNAME - <%= @name %>: Logs are in: <% @logdir.each do |item| %><%= item %><% end %>"
<% @logdir.each do |item| -%>
show_command "ls -latr <%= item %>"
show_command "df <%= item %>"
<% end -%>
<% end -%>

<% if @logfile != "" -%>
# Show logs
echo_title "$HOSTNAME - <%= @name %>: Last log entries: <% @logfile.each do |item| %><%= item %><% end %>"
<% @logfile.each do |item| -%>
<% if @verbose == "yes" -%>
show_command "tail -30 <%= item %>"
<% else -%>
show_command "tail -10 <%= item %>"
<% end -%>
<% end -%>
<% end -%>

<% if @run != "" -%>
echo_title "$HOSTNAME - <%= @name %>: Extra info"
<% @run.each do |cmd| %>show_command "<%= cmd %>"
<% end -%>
<% end -%>


<% if @servicename != "" -%>
# Show service info
echo_title "$HOSTNAME - <%= @name %>: Services: <% @servicename.each do |item| %><%= item %><% end %>"
<% @servicename.each do |item| -%>
show_command "/etc/init.d/<%= item %> status"
<% end -%>
<% if @verbose == "yes" -%>
show_command "ps -adef | grep <%= @processname %> | grep -v grep"
<% else -%>
show_command "ps -adef | grep <%= @processname %> | grep -v grep | head -20"
<% end -%>
<% @port.each do |mport| -%>
<% if @verbose == "yes" -%>
show_command "netstat -natup | grep ':<%= mport %> '"
<% else -%>
show_command "netstat -natup | grep ':<%= mport %> ' | head -20"
<% end -%>
<% end -%>
<% end -%>
