Tuesday, July 30, 2019

vSphere HA agent for this host has an error: The vSphere HA agent is not reachable from vCenter Server


One day, ESXi 6.5 started reporting:
vSphere HA agent for this host has an error: The vSphere HA agent is not reachable from vCenter Server

I fixed it by disabling "vSphere HA" and then enabling "vSphere HA".

Friday, February 15, 2019

Easy Puppet Templates

I could not find a simple example to get me started with puppet's templating feature. It turns out that it's a lot easier than you'd think but all I could find was super detailed instructions. So if you're looking for an easy working example, give this a try. Otherwise, there's other more complex and detailed instructions out there.

This module manages check_mk.ini on windows server. Sometimes, you might have the need to have a different check on a specific windows server.

Structure:
- modules (your root module directory)
  - mymodule (your module directory)
    - template (create this directory to hold your template file)
      - check_mk.ini.epp (create this file. It is your template.)

The contents of check_mk.ini.epp:
#check_mk.ini:
# Managed by puppet
# any changes will be reverted
#
[mrpe]
    # Run classical monitoring plugins. The word before the command
    # line is the service description for the monitoring. Use backslashes
    # in Windows-paths.
    # check = Dummy mrpe\check_crit
    # check = IP_Configuration mrpe\check_ipconfig 1.2.3.4
    # check = Whatever c:\myplugins\check_whatever -w 10 -c 20
    #
<%# This is a comment %>
<%- if $facts[fqdn] == "myserver01.mydomain.com" { -%>
    check = Report_Server c:\plugins\check_report.bat
<% } -%>
<%- if $facts[fqdn] == "myserver02.mydomain.com" { -%>
    check = Report_Server c:\sbin\check_old_report.bat
<% } -%>

    check = guest_user c:\plugins\check_guestuser.bat

Explanation of the check_mk.ini.epp file:
if your server's fully qualified domain name is myserver01.mydomain.com, then add the line:
check = Report_Server c:\plugins\check_report.bat

otherwise

if your server's fully qualified domain name is myserver02.mydomain.com, then add the line:
 check = Report_Server c:\sbin\check_old_report.bat

always add the following line because it's not constrained by any 'if' statements:
 check = guest_user c:\plugins\check_guestuser.bat

What's inside the manifest:

    file { "C:\\Program Files (x86)\\check_mk\check_mk.ini":
      ensure  => file,
      content => epp('mymodule/check_mk.ini.epp'),
    }

Troubleshooting:
If puppet isn't recognizing your facts, run "facter" at the command prompt. Look at your fact. Does it look exactly as you typed?
Example: 
If facter says
fqdn => "myserver01.mydomain.com"
then, use "myserver01.mydomain.com"

otherwise, if facter says
fqdn => myserver01.mydomain.com
then, use myserver01.mydomain.com

Summary:
As you can see, it's pretty simple. Hopefully, this will get you going and then, reading the more indepth docs/tutorials will make more sense.

Sylink:(EXCEPTION, err=2) AH: failed to send request...

Symantec Endpoint Protection Client started failing to update its anti-virus definition. After enabling debug logging, all I can see is:

Sylink:(EXCEPTION, err=2) AH: failed to send request...

I launched wireshark and I see no communication errors. I rebooted the server to no avail. Then, I did some tinkering and for whatever reason, it started working. I don't know what exactly fixed it but here you go:

1) run smc.exe -stop
2) run smc.exe -start
3) Launch Symantec Endpoint Protection
4) in the tray icon, right click the symantec icon and click 'Disable Symantec Endpoint Protection'
5) wait a few seconds and the client UI will turn red and tell you that everything is disabled
6) click Fix All and wait
7) in a few seconds, the client UI will go back to being orange
8) click Fix
9) go look at the debug log and you won't see anymore errors
10) in a few minutes, the client UI will turn green

Saturday, August 19, 2017

puppet :: How to run bginfo via the scheduler

I won't go in to details about bginfo. There are plenty of articles on the internet about bginfo. I won't go in to details about the scheduler either for the same reason. In this blog post, I will explain how I use puppet to tell the scheduler to run bginfo.

The first thing you need to do is to install bginfo.exe somewhere and then configure bginfo to display the statistics you want. Then, create a scheduled task to run bginfo.exe at logon (for what user or maybe all users who log on). You can also tell the scheduler to execute every 5 minutes while the user is logged on. That way, while the user is logged on, the information stays fresh and if the user is not logged on, don't waste cpu cycles.

Now that you've got it running successfully on one of your servers, all you need to do is export your bginfo xml template file and your scheduled task. Place those two files on your puppet server.


In your puppet module, use this code to import the scheduled task.

 file {
    "c:\\sbin":
      ensure => directory,
  }

  file {
    "c:\\sbin\\Bginfo.exe":
      ensure  => present,
      require => File["c:\\sbin"],
      source  => "puppet:///modules/sysinternals/Bginfo.exe",
  }

  file {
    "c:\\sbin\\mycustomFile.bgi":
      ensure => present,
      require => File["c:\\sbin\\Bginfo.exe"],
      source  => "puppet:///modules/sysinternals/mycustomFile.bgi",
  }

  file {
    "c:\\sbin\\bginfo.xml":
      ensure  => present,
      require => File["c:\\sbin\\mycustomFile.bgi"],
      source  => "puppet:///modules/sysinternals/bginfo.xml",
  }

  exec {
    "schtasks_bginfo":
      command => "c:\\Windows\\System32\\schtasks.exe /Create /XML c:\\sbin\\bginfo.xml /TN bginfoFG2",
      unless  => "c:\\Windows\\System32\\schtasks.exe /Query /TN BginfoFG2",
      require => File["c:\\sbin\\bginfo.xml"],
  }



puppet :: How to copy a file only if an account exists

I scoured the internet to see if anyone had already done something like this. I couldn't believe that I found nothing. The only bits I found was for, if another file exists or if a directory exists.

Anyway, this is how I did it.

First step I did was to create a custom fact. I named the custom fact isoracle. Then, in my class, I checked to see if isoracle true or false. If isoracle true, I copied the file.

The custom fact goes in this file:
./modules/files4all/lib/facter/isoracle.rb

The contents of the file is:
Facter.add(:isoracle) do
  setcode do
    isoracle = Facter::Util::Resolution.exec('id oracle 2>/dev/null')
    if isoracle == ""
      isoracle = false
    else
      isoracle = true
    end
  end
end

The class file goes in this file:
./modules/files4all/manifests/oracle.pp

The contents of this file is:
class files4all::oracle {

#Check the custom fact to see if oracle account exists
#skip if oracle account does not exists
  if $isoracle == true {
#These are the defaults unless overridden
    File {
      ensure => "present",
      owner  => "oracle",
      group  => "oracle",
      mode   => "0644",
    }

    file {
      [ "/oracle", "/oracle/sbin" ]:
      mode   => "0755",
      ensure => "directory",
    }

    file { "/oracle/testfile":
      source => "puppet:///modules/files4all/oracle/testfile",
    }

  }

}

What will happen is, puppet will first copy the isoracle.rb file to the client and run it. From there, puppet will be able to determine if the oracle account exists or not. I suppose you could modify the code to check for anything you want.

Friday, April 22, 2016

How to import a CSV in to Grafana

I was given a CSV and I needed to import this file in to Grafana.

I found that I couldn't actually import data directly in to Grafana because Grafana needs a data source. The data source already setup was Graphite so all I did was send the data to Graphite and sure enough, the data showed up in Grafana. There are some kinks I had to work with though and I'll explain.

First of all, if your data is older than your Graphite's retention period, nothing will show up in Grafana. So, modify the date/time to something that will fall in your retention period. However, do keep in mind that this date/time is going to be used by Grafana to represent your data. I would imagine that you could also just tell Graphite to extend the retention period. That leads us to the next gotcha.

So, you've extended your retention period but it still doesn't work. What now? Well, it turns out that you can't just extend your retention period in your Graphite configs. You have to actually tell the whisper file as well. Read the docs here "http://graphite.readthedocs.org/en/latest/config-carbon.html" and look for whisper-set-aggregation-method.py for an example.

Cool. Now that it's taken cared of, you can start sending data in to Graphite (see http://graphite.readthedocs.org/en/latest/feeding-carbon.html ).

Alright, according to the above documentation, I should be able to do the following...
echo "local.random.diceroll 4 `date +%s`" | nc -q0 myserver 2300
Sure enough, typing this and pressing enter makes some data show up in Graphite (and ultimately, Grafana). The next thing I needed to do was to send hundreds of lines with 31 fields in to Graphite. No way was I going to type it up one by one. So I cooked up a quick and dirty script to do it for me.

I took the headers out of the CSV file and placed it in to a separate file called sampleheaders.csv. I deleted the headers out of the CSV file. Below is the script I came up with.

#!/bin/bash
#Set an original starting time in EPOCH
#Then, set a starting time in EPOCH
#Calculate your own EPOCH as this date/time is for demonstration purposes only
ostarting=1450944001
starting=1450944001

#Grab all the headers from the sample headers file
headers=`head -1 sampleheaders.csv`

#There are 31 fields so we have to loop through each one (hard coded but it's quick and dirty)
for i in {1..31};do

#Set the starting point to the original starting point
starting=$ostarting

#print each line one by one and only grab the field we're working on
 for x in `cat fsample.csv | awk -F , -v var=$i '{print $var}'`;do

#get the header that we're on
#i.e. if we're on loop 3, then get field 3 of the headers
newvar=$(echo $headers | awk -F , -v myvar=$i '{print $myvar}' | sed "s/\"//g")

#echo out the header field in $newvar + the value in $x + the time in $starting
#This first echo is only for verbosity
#It is the second echo that actually pipes to nc
echo "comps.test1.$newvar $x $starting | nc -q0 localhost 2003"
echo "comps.test1.$newvar $x $starting" | nc -q0 localhost 2003
#increment the starting time by 86,400 seconds (about 24hrs)
#that way, the data is plotted one day after another.
 starting=$( echo "${starting}+86400" | bc -l )
 done

done

Monday, April 11, 2016

How to add a host using check_mk web api

check_mk has a web api that you can use to add hosts from the command line. The documentation is here:
http://mathias-kettner.com/checkmk_wato_webapi.html

I went searching for a bash script in hopes that someone may have already created one. No luck. So, I created my own. You can find it on github here:
https://github.com/gyang2300/cmk-add-host/blob/master/cmk-add-host.sh