Powershell to get the output for each computer in specific format - output

Trying to get the HP Firmeware details using the HP cmdlets from mutliple Enclousre.
When the below command is execute the result is .
C:\WINDOWS\system32> $new = $rus | Select-Object -ExpandProperty EnclosureComponentFirmwareInformation
C:\WINDOWS\system32> $new
Result:
Device : TRAY
Name : BladeSystem c7000 Onboard Administrator Tray
Location :
Version : 1.7
NewVersion : 1.7
Device : LCD
Name : BladeSystem c7000 Insight Display
Location :
Version : 2.2.2
NewVersion : 2.2.2
Device : FAN
Name : Active Cool 200 Fan
Location : 1
Version : 2.9.4
NewVersion : 2.9.4
When I try to take the result from multiple computer the result is:
C:\WINDOWS\system32> $new = $rus | Select-Object -Property IP,EnclosureComponentFirmwareInformation
C:\WINDOWS\system32> $new
IP EnclosureComponentFirmwareInformation
-- -------------------------------------
1.1.1.1 {#{Device=TRAY; Name=BladeSystem c7000 Onboard Administr...
1.1.1.2 {#{Device=TRAY; Name=BladeSystem c7000 Onboard Administr...
I used Hash table format
C:\WINDOWS\system32> $new = $rus | Select-Object -Property IP,#{Label="Device";Expression={[string]($_.EnclosureComponen
tFirmwareInformation.device)}},#{LAbel="Name";Expression={[string]($_.EnclosureComponentFirmwareInformation.Name)}},#{LA
bel="Location";Expression={[string]($_.EnclosureComponentFirmwareInformation.Location)}}
C:\WINDOWS\system32> $new
IP Device Name Location
-- ------ ---- --------
1.1.1.1 TRAY LCD FAN FAN FAN FAN F... BladeSystem c7000 Onboard ... 1 2 3 4 5 6 7 8 9 10
1.1.1.2 TRAY LCD FAN FAN FAN FAN F... BladeSystem c7000 Onboard ... 1 2 3 4 5 6 7 8 9 10
But i need result like the first output for each server.
IP
1.1.1.1
Device Name Location
Tray BladeSystem 1
LCD Bladesystem 2
FAN Bladsystem.. 3
1.1.1.2
Device Name Location
Tray BladeSystem 1
LCD Bladesystem 2
FAN Bladsystem.. 3
Pls let me know how can i modify my output..

Related

Need help on concept for database with kind of recursive data

I have data which describes maintain specifications for devices. To make it easy lets say I get the following specs from the global engineering team:
Device A: Needs 3 maintain jobs a year
Device B: Needs 4 maintain jobs a year
Device C: Needs 5 maintain jobs a year
Device D: Needs 6 maintain jobs a year
Now it is possible that a Pole like EMEA (Europe/Middle East/Africa) is changing some of this specs to fulfill their legal rights. eg.
Device A: Needs 3 maintain jobs a year
Device B: Needs 2 maintain jobs a year
Device C: Needs 4 maintain jobs a year
Device D: Needs 6 maintain jobs a year
Not enough, Germany will also have some changes depending on the changes EMEA did:
Device A: Needs 3 maintain jobs a year
Device B: Needs 2 maintain jobs a year
Device C: Needs 1 maintain jobs a year
Device D: Needs 6 maintain jobs a year
This can lead further to county, city etc. So it would be a good idea to make it endless and not fix in layers.
To store the connecting data I thought I will setup two tables like
table stages
id INT PRIMARY KEY AUTOINCREMENT
name VARCHAR(100)
table stagetypes
id INT PRIMARY KEY AUTOINCREMENT
name INT
stage INT
priority INT
which will hold the entries
table stages
1 Global
2 EMEA
3 Germany
4 Bavaria
5 Munich
table stagetypes
1 1 null 0 // Global setup on nothing priority 0
2 2 2 1 // EMEA setup on EMEA priority 1
3 2 1 0 // EMEA setup on Global priority 0
4 3 3 2 // Germany setup on Germany priority 2
5 3 2 1 // Germany setup on EMEA priority 1
6 3 1 0 // Germany setup on Global priority 0
With this tables I can easily query the needed stages for a given stage. Lets say for Germany I can get all needed stages with
SELECT sstage.stage
FROM stagetypes
JOIN stages AS mstage ON (stage.id = stagetypes.name)
JOIN stages AS stage ON (stage.id = stagetypes.stage)
WHERE mstage.name = 'Germany'
ORDER BY stagetypes.priority DESC
Result will be an array with
Germany, EMEA, Global
So far so good.
Now I can create a specification table:
table specs
id INT PRIMARY KEY AUTOINCREMENT
device VARCHAR(100)
numberofvisits INT
stage INT
and fill it with data like
table specs
1 DeviceA 3 1
2 DeviceB 4 1
3 DeviceC 5 1
4 DeviceD 6 1
5 DeviceB 2 2 // Change for EMEA
6 DeviceC 4 2 // Change for EMEA
7 DeviceC 1 3 // Change for Germany
But now I have no idea how to fetch the specs for Germany of all Devices.
Result should be
1 DeviceA 3 1
4 DeviceD 6 1
5 DeviceB 2 2
7 DeviceC 1 3
So how can I design the specs table to get this data with a most simple query? Or do you have a complete different approach to solve this problem?
At the end I am restricted to use mySQL5.7 or OracleSQL11. So ranking is not a possible solution :(
Ranking rows in a modern DBMS (Oracle, PostgreSQL, MySQL starting with version 8, SQL Server, etc.) is very easy with the ROW_NUMBER function.
If the data model were this:
institutions
+----------------+---------+----------+
| institution_id | name | priority |
+----------------+---------+----------+
| 1 | Global | 0 |
| 2 | EMEA | 1 |
| 3 | Germany | 2 |
+----------------+---------+----------+
setups
+-----------+---------------+-----------+
| device_id | instituion_id | job_count |
+-----------+---------------+-----------+
| A | 1 | 3 |
| B | 1 | 4 |
| C | 1 | 5 |
| A | 2 | 3 |
| B | 2 | 2 |
| A | 3 | 3 |
+-----------+---------------+-----------+
then you'd select the most relevant setup per device as follows:
select *
from setups s
join institutions i using (instituion_id)
order by row_number() over (partition by s.device_id order by i.priority desc)
fetch first rows with ties;
(This is standard SQL syntax and should work in Oracle and PostgreSQL. For SQL Server and MySQL you'd write the query a little different.)
Using an old DBMS such as MySQL 5 just makes writing the query a tad more clumsy, that's all. Here is a solution with NOT EXIST (get the setups where not exists a better setup for the device):
select *
from setups s
join institutions i using (instituion_id)
where not exists
(
select null
from setups sx
join institutions ix using (instituion_id)
where sx.device_id = s.device_id
and ix.priority > i.priority
);

apache/mysql generate too many request on amazon centos

My issue is, my website open too many connections in mysql server this is hanged my website and also generate many requests on apache. i have installed the apache module mod-evasive and mod-security i have also empty the iptables rules basically i am using amazon ec2 so it gives security ip i have blocked all outbound and inbound i have opened only 443,80 and ssh 22 port only but still when i take netstat it shows
netstat -anp |grep 'tcp\|udp' | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
4 --0.0.0.0
4 ---119.159.195.199
25 ---54.69.254.252
374 ---
on above my question is why my server 374 apache connection on ::1:80 how can block this or reduce this
mysql connection stat are
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| Connections | 5208 |
| Threads_cached | 0 |
| Threads_connected | 54 |
| Threads_created | 5207 |
| Threads_running | 54 |
+-------------------+-------+
5 rows in set (0.00 sec)
my second question is why my sql connections is increasing.
Please any one help me i will really appreciated.

Create an Equinox instance of Karaf

I am running Karaf 3.0.1 with Equinox core. Now I want to create a new instance which also runs Equinox core. I have tried:
instance:create test
The created instance runs Felix core so I tried to update its configuration ${karaf.home}/instances/test/etc/config.properties. After adjusting, whenever I tried to connect to this instance, I received:
karaf#root: instance:connect test
Connecting to host localhost on port 8105
Error executing command: Failed to get the session
What wrong did I do? and Is there another way to create a Equinox core instance?
Use instance:clone rather than instance:create
Make sure you start the instance after you've created / cloned it
before trying to connect.
i.e.
karaf#root()> bundle:list -t 0 | grep '^ 0'
0 | Active | 0 | 3.8.2.v20130124-134944 | OSGi System Bundle
karaf#root()> instance:clone root test
karaf#root()> instance:list
SSH Port | RMI Registry | RMI Server | State | PID | Name
-------------------------------------------------------------
8101 | 1099 | 44444 | Started | 29306 | root
8101 | 1099 | 44444 | Stopped | 0 | test
karaf#root()> instance:ssh-port-change test 8102
karaf#root()> instance:rmi-server-port-change test 44445
karaf#root()> instance:rmi-registry-port-change test 1100
karaf#root()> instance:list
SSH Port | RMI Registry | RMI Server | State | PID | Name
-------------------------------------------------------------
8101 | 1099 | 44444 | Started | 29306 | root
8102 | 1100 | 44445 | Stopped | 0 | test
karaf#root()> instance:start test
karaf#root()> instance:connect test
Connecting to host localhost on port 8102
Connecting to unknown server. Automatically adding to known hosts.
Storing the server key in known_hosts.
Password: *****
Connected
__ __ ____
/ //_/____ __________ _/ __/
/ ,< / __ `/ ___/ __ `/ /_
/ /| |/ /_/ / / / /_/ / __/
/_/ |_|\__,_/_/ \__,_/_/
Apache Karaf (3.0.2)
Hit '<tab>' for a list of available commands
and '[cmd] --help' for help on a specific command.
Hit 'system:shutdown' to shutdown Karaf.
Hit '<ctrl-d>' or type 'logout' to disconnect shell from current session.
karaf#test()> bundle:list -t 0 | grep '^ 0'
0 | Active | 0 | 3.8.2.v20130124-134944 | OSGi System Bundle
karaf#test()>

Move pointer in MS Access

I am trying to figure out how i can let MS Access use a field value that is 3 rows lower.
The data is from an external source which retrieves SNMP data every week. I linked a table in Access to the txt output file.
Here is a sample:
| Device | IP Address | Uptime | SNMP Custom |
--------------------------------------------------
| Router | 192.168.. | 1 day, 1h | IOS version |
Now when i want to get more information of the devices, Cisco descided it was needed to add new lines to the output file so now the linked table looks like:
| Device | IP Address | Uptime | SNMP Custom | SNMP Custom 2
-----------------------------------------------------------------
| Router | 192.168.. | 1 day, 1h | IOS version |
| Technical Support: sometext
| Copyright (c) sometext
| Compiled | ABCD
Now those 4 lines are from 1 device and the ABCD should be in the SNMP Custom 2 field. The exessive rows i can simply delete but i have no idea how to move the ABCD value to the SNMP Custom 2 field.
Can this be done using MS Access(VB?) or classic ASP? Any thoughts are greatly appreciated.
Thanks in advance
If I've understood your OP correctly, try try the following in an Access query:
UPDATE myTable SET [SNMP Custom 2] = [IP Address], [IP Address] = "" WHERE [Device] = "Compiled"

Unable to understand this strange MySql client behavior

I'm not sure what's going on here with the line art output by /usr/bin/mysql here.
The problem: I'm unable to redirect the line art (used in creating the table columns) to a file!
First, I do this on my terminal.
[sd#host:~/tmp]
$ mysql -usd sd -e 'select * from loan;'
+---------+--------------+--------+
| loan_no | branch_name | amount |
+---------+--------------+--------+
| L-11 | Round Hill | 900 |
| L-14 | Downtown | 1500 |
| L-15 | Perryridge | 1500 |
| L-16 | Perryridge | 1300 |
| L-17 | Downtown | 1000 |
| L-23 | Redwood | 2000 |
| L-93 | Mianus | 500 |
+---------+--------------+--------+
Now, I want this whole blessed thing printed above captured, so I redirect stdout and stderr to the file 'out', like so:
[sd#host:~/tmp]
$ mysql -usd sd -e 'select * from loan;' >out 2>&1
As you can see below, the line art is completely missing!
[sd#host:~/tmp]
$ cat out
loan_no branch_name amount
L-11 Round Hill 900
L-14 Downtown 1500
L-15 Perryridge 1500
L-16 Perryridge 1300
L-17 Downtown 1000
L-23 Redwood 2000
L-93 Mianus 500
More proof that the line art is REALLY missing! (The -T option prints tabs, if any.)
[sd#host:~/tmp]
$ cat -T out
loan_no^Ibranch_name^Iamount
L-11^IRound Hill^I900
L-14^IDowntown^I1500
L-15^IPerryridge^I1500
L-16^IPerryridge^I1300
L-17^IDowntown^I1000
L-23^IRedwood^I2000
L-93^IMianus^I500
So, my question is, how the heck does mysql know who -- whether a terminal or a text file -- is sucking its output from 'its rear end' :-) ?
Program can determine whether output stream is terminal or
not using isatty (3) function.
MySQL uses this information to change its output (see man mysql, "-t" option produces table output for non-interactive mode too)
It knows
The situation is analogous to
$ ls
tom dick harry
and
$ ls > out
$ cat out
tom
dick
harry