Wednesday, June 15, 2016

Iot - from different angle

IoT - Internet of Things
It's not only that you open the door and get the temperature.
It's like whenever a mother want she can get her baby's health condition instantly without touching her, Seem funny.
A kind of trend analysis where a device is so much intelligent that it can give exact figure of her baby.

It include data analytics based on trends and about developing such level of automation where it can check any device.
In the IoT world device will contact with each other like without calling my friend i will inform him that i am coming to his doorstep and if he do not like me his device will answer that he is not at home :)

It can be helpfull in heavy machinaries like Gas filtering machine is very complex and you need to check each and every pump to predict it's future behaviour, example you need to send small drone through out the gas pipe to check health,
drone will move and stop at each corner and contact with IoT sensor about its health, it would collect all the required data and after come back push it back to the system to further analysis, if anything suspecious found it would send alert to the mechanic

Thursday, June 9, 2016

Check server connectivity through powershell

$srvname= "srv1","srv2","srv3","srv4","srv5"


foreach ($item in $srvname)

{

if (test-Connection -ComputerName $Server -Count 3 -Quiet )
{

write-Host "Server is Pinging "
       
}

else
                   
{

Write-Warning "Server is not pinging"
           
}   
       
}
 

Check disk space through powershell

$credget-Credential
$computersget-Content c:\neeraj\complist.txt
 
foreach ( $item in $computers) { 
get-WmiObject win32_logicaldisk -Credential $cred -ComputerName $item -Filter "Drivetype=3"  |  
ft SystemName,DeviceID,VolumeName,@{Label="Total SIze";Expression={$_.Size / 1gb -as [int] }},@{Label="Free Size";Expression={$_.freespace / 1gb -as [int] }} -autosize 
} 

Send email through powershell

 
$smtpserver"your-exchange-server" 
 
$to = "neerajvayu123@gmail.com" 
 
$from = "neerajvayu123@gmail.com" 
 
$subject = "First email"  
 
$body = "HI $to ,
" 
 
$body +"How are you doing, i am testing email function 
" 
  
send-MailMessage -SmtpServer $smtpserver -To $to -From $from -Subject $subject -Body $body -BodyAsHtml

ReCycle bin cleanup through command

Clear-RecycleBin -Confirm:$false

Tuesday, June 7, 2016

Multiple vCenter alarm at one place through PowerCLI

Write a power shell function to do this and save it as Get-TriggeredAlarms.ps1 script 
run it with this command.\Get-TriggeredAlarms -vCenters vc001,vc002
 
 
 
#Script:-
 
param (
 [String[]]$vCenters
)
 
Function Get-TriggeredAlarms {
 param (
  $vCenter = $(throw "A vCenter must be specified."),
  [System.Management.Automation.PSCredential]$credential
 )
 
 if ($credential) {
  $vc = Connect-VIServer $vCenter -Credential $credential
 }
 else {
  $vc = Connect-VIServer $vCenter
 }
 
 if (!$vc) {
  Write-Host "Failure connecting to the vCenter $vCenter."
  exit
 }
 $rootFolder = Get-Folder -Server $vc "Datacenters"
 
 foreach ($ta in $rootFolder.ExtensionData.TriggeredAlarmState) {
  $alarm = "" | Select-Object VC, EntityType, Alarm, Entity, Status, Time, Acknowledged, AckBy, AckTime
  $alarm.VC = $vCenter
  $alarm.Alarm = (Get-View -Server $vc $ta.Alarm).Info.Name
  $entity = Get-View -Server $vc $ta.Entity
  $alarm.Entity = (Get-View -Server $vc $ta.Entity).Name
  $alarm.EntityType = (Get-View -Server $vc $ta.Entity).GetType().Name 
  $alarm.Status = $ta.OverallStatus
  $alarm.Time = $ta.Time
  $alarm.Acknowledged = $ta.Acknowledged
  $alarm.AckBy = $ta.AcknowledgedByUser
  $alarm.AckTime = $ta.AcknowledgedTime  
  $alarm
 }
 Disconnect-VIServer $vCenter -Confirm:$false
}
 
Write-Host ("Getting the alarms from {0} vCenters." -f $vCenters.Length)
 
$alarms = @()
foreach ($vCenter in $vCenters) {
 Write-Host "Getting alarms from $vCenter."
 $alarms += Get-TriggeredAlarms $vCenter
}
 
$alarms | Out-GridView -Title "Triggered Alarms" 

 
 

Powercli get vmware alarm

#get alarm info of multiple host server
Get-AlarmDefinition -Server Server1, Server2

#to get all the server alarm of a vcenter use  below script.
$alrm=get-vmhost
foreach($host in $alrm)
{
Get-AlarmDefinition -Server $host.name
}

#to get information of specific alarm, it will Extract all PowerCLI supported alarm actions for the default alarm "Host processor status".

Get-AlarmDefinition -Name "Host processor status" | Get-AlarmAction -ActionType "ExecuteScript", "SendSNMP", "SendEmail"

#Extract the alarm actions for the default alarm "Host processor status" by specifying the alarm by name.

Get-AlarmAction -AlarmDefinition "Host processor status" -ActionType "SendSNMP" -Server 'server IP'


#Get-AlarmDefinition is a typical PowerCLI getter.
#It returns all the alarms defined on the vCenter Servers you’re connected to.
Get-AlarmDefinition # This will return all the defined alarms on the servers you’re connected to

#This will return all the disabled alarm definitions with names starting with “virtual machine”
Get-AlarmDefinition -Name "virtual machine*" -Enabled $false

#This will return all alarms that apply to the host “hostname”.
#This includes alarms defined on this host and alarms inherited from the parent entity, or from any ancestors in the inventory hierarchy.
Get-VMHost hostname | Get-AlarmDefinition

#Here’s how you can modify an alarm definition:

#This will rename the alarm to “Host memory” and disable it
Get-AlarmDefinition "Host memory status" | Set-AlarmDefinition -Name "Host memory" -Enabled $false

#The main part of the alarm definitions you can manage is an alarm’s actions configuration.
#You can create an alarm action this way:
#This will create a send email action which will be triggered once when the alarm state changes from warning (yellow) to alert (red)
Get-AlarmDefinition "Host storage status" | New-AlarmAction -Email -To “me@mycompany.com” -Subject "Host storage shortage"

H#ere is how you can add another action trigger, which will fire earlier – when the alarm state changes from normal (green) to alert (yellow):
#Get the action we previously created
$action = Get-AlarmDefinition "Host storage status" | Get-AlarmAction -ActionType SendEmail

#Add a new repeating trigger to the action
$action | New-AlarmActionTrigger -StartStatus Green -EndStatus Yellow –Repeat

#You can also set the interval at which the action is repeated:
#This will configure the send email action to repeat once a day (as long as the alarm is in the yellow state)
Set-AlarmDefinition "Host storage status" -ActionRepeatMinutes (60 * 24)

#Finally you may want to remove certain alarm actions. You can do it this way:
$action = Get-AlarmDefinition "Host storage status" | Get-AlarmAction -ActionType SendEmail
Remove-AlarmAction -AlarmAction $action

#This is what you can do with the newly introduced cmdlets.
#The PowerCLI team has decided that the rest of the alarm functionality will not be reconfigured often enough to add cmdlets for the task.
#However you can always gain full control over the situation through the alarm’s View object.
#Here’s how you can change alarm configuration that is not available to change through the cmdlets:
#Get the alarm’s view
$alarmDefinition = Get-AlarmDefinition "Host storage status"

$alarmSpecification = $alarmDefinition. ExtensionData

#Make the desired alarm configuration changes
$alarmSpecification. Description="advanced-set description…..”

#Update the alarm

$alarmView = Get-View $alarmSpecification.Alarm

$alarmView.ReconfigureAlarm( $alarmSpecification )

Content of this blog has been moved to GITHUB

Looking at current trends and to make my content more reachable to people, I am moving all the content of my blog https://tech-jockey.blogsp...