MAL - Memória Auxiliar do Lutieri

quarta-feira, novembro 11, 2009

some vbscript for Nagios checks

Detect if media is connected to a interface:



aStatusStr = Split("Disconnected,Connecting,Connected,Disconnecting," _
& "Hardware not present,Hardware disabled,Hardware malfunction," _
& "Media disconnected,Authenticating,Authentication succeeded," _
& "Authentication failed,Invalid address,Credentials required", ",")

strComputer = "."
Set oWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer _
& "\root\cimv2")

Set cItems = oWMI.ExecQuery("Select * from Win32_NetworkAdapter"_
& " where AdapterTypeID = 0") ' 0 = Ethernet 802.3

For Each oItem in cItems
''if Instr(oItem.NetConnectionID, "LAN") > 0 then

if oItem.NetConnectionID <> "" then

output = output & oItem.NetConnectionID & ": "_
& aStatusStr(oItem.NetConnectionStatus) & " * "

End if
''End if
Next

Wsh.echo output
WScript.Quit(0)
''' Source: http://msdn.microsoft.com/en-us/library/aa394216%28VS.85%29.aspx




Detect which node is the Active and Passive in a Windows Cluster environment:



set WshShell = CreateObject( "WScript.Shell" )

Set objNet = CreateObject("WScript.NetWork")

Dim strComputerName
strComputerName = objNet.ComputerName


sExe = "cluster resource ""cluster ip address"""
with CreateObject("WScript.Shell")
with .Exec(sExe)
with .StdOut
do until .AtEndofStream
s = s & Replace(.ReadLine, vbcr, "") _
& vbNewLine
Loop
end with ' StdOut
end with ' Exec
end with ' Shell

'wsh.echo s
Result = InStr(1, s, strComputerName, VBTEXTCOMPARE)


if Result <> 0 then
WScript.echo strComputerName & " is the ACTIVE"
Else
WScript.echo strComputerName & " is the PASSIVE"
end if

WScript.Quit(0)

Marcadores: ,

segunda-feira, abril 09, 2007

Permissões no check_dhcp do Nagios

Falando em Nagios aprenda a pronunciar:

http://www.nagioscommunity.org/2007/02/20/nagios-pronunciation/

Documentação do Nagios completa:

PT_BR: http://nagios.speed.dcc.ufmg.br/docs/index.html


Bom... enfim...

Dentro da pasta libexec do Nagios estão contidos os binários para fazer as checagens. Estava com um problema quanto a checagem DHCP. Já que é necessário criar um socket com porta alta para fazer a busca na rede, usuários comuns não tem permissão de criar tais sockets. Acaba retornando a mensagem:

Error: Could not bind socket to interface eth0. Check your privileges...

A solução foi simples.

#chmod 4755 /usr/local/nagios/libexec/check_dhcp
#chown root /usr/local/nagios/libexec/check_dhcp


Ativei o bit especial suid(4000) para o binário e alterei o dono para root. Assim quando ele for chamado por qualquer usuário ele será executado como root. ;-)

Fui-me!

Marcadores: ,



Chat with Lutieri G. B.

Subscribe in a reader